home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / doc / chap12.doc < prev    next >
Text File  |  1993-07-05  |  267KB  |  9,328 lines

  1. dice/abort                                                        dice/abort
  2.  
  3.     FUNCTION
  4.         abort a program (exiting with an error)
  5.  
  6.     LIBRARY
  7.         TBA
  8.  
  9.     SYNTAX
  10.         #include <TBA.h>
  11.         void abort(void);
  12.  
  13.     DESCRIPTION
  14.         abort aborts a program with a non-zero exit code.  The default abort
  15.         routine in c.lib does the equivalent of an exit(20);. The programmer
  16.         may overide the default abort routine with his own.
  17.  
  18.     INPUTS
  19.         none
  20.  
  21.     RESULTS
  22.         abort never returns
  23.  
  24.     SEE ALSO
  25.         assert
  26.  
  27.     EXAMPLE
  28.         #include <stdio.h>
  29.         #include <stdlib.h>
  30.         main(ac, av)
  31.         int ac;
  32.         char **av;
  33.         {
  34.            if (ac == 1)
  35.            {
  36.               puts("Expected an argument!");
  37.               abort();
  38.               }
  39.               puts("Thanks!");
  40.               return(0); 
  41.         }
  42.  
  43. dice/abs,labs                                                  dice/abs,labs
  44.  
  45.     FUNCTION
  46.         take absolute value
  47.  
  48.     LIBRARY
  49.         TBA
  50.  
  51.     SYNTAX
  52.         #include <stdio.h>
  53.         #include <stdlib.h>
  54.         int r = [l]abs(n);
  55.         int n;
  56.  
  57.     DESCRIPTION
  58.         abs takes the absolute value of an int; labs takes the absolute value
  59.         of a long.  Both return the absolute value of the specified integer. 
  60.         For example, r = n if n >= 0, r = -n (positive) if n < 0. Normally one
  61.         would not use this call due to overhead, but it exists for
  62.         compatibility.
  63.  
  64.         || WARNING! The absolute value of 0x80000000 cannot be taken.
  65.         || 0x80000000 will be returned.
  66.  
  67.         :: NOTE: UNDER DICE, sizeof(int) == sizeof(long) and these two
  68.         :: functions are thus identical.
  69.  
  70.     INPUTS
  71.         int n;     integer
  72.  
  73.     RESULTS
  74.         int r;     absolute value of integer
  75.  
  76.     SEE ALSO
  77.         TBA
  78.  
  79.     EXAMPLE
  80.         #include<stdio.h>
  81.         #include <stdlib.h>
  82.         main()
  83.         {
  84.            int n = -53;
  85.            printf("The absolute value of %d is %d\n", n, abs(n));
  86.            sleep(1);
  87.            printf("But its faster if you write a macro:\n");
  88.            #define abs(x)  (((x) < 0) ? -(x) : (x))
  89.            sleep(1);
  90.            printf("The absolute value of %d is %d\n", n, abs(n));
  91.            return(0);
  92.         }
  93.  
  94. dice/access                                                      dice/access
  95.  
  96.     FUNCTION
  97.         determine whether file is accessable
  98.  
  99.     LIBRARY
  100.         TBA
  101.  
  102.     SYNTAX
  103.         #include <TBA.h>
  104.         int r = access(filename, mode);
  105.         const char *filename;
  106.         int mode;
  107.  
  108.     DESCRIPTION
  109.         access returns 0 upon success, -1 if access with the requested modes
  110.         was impossible.  The filename serves as a pointer to the string of the
  111.         filename we wish to check, and the modes are what we expect the file
  112.         to be able to do.  The modes may be one or more of the following OR'd
  113.         together.
  114.  
  115.          0   check for existance of file only
  116.          1   check execute permission for file
  117.          2   check write permission for file
  118.         4  check read permission for file
  119.  
  120.     INPUTS
  121.         char *filename;     file to check
  122.  
  123.         int mode;     modes as specified above
  124.  
  125.     RESULTS
  126.         int r;      0 if modes available, -1 if not
  127.  
  128.     SEE ALSO
  129.         open, fopen
  130.  
  131.     EXAMPLE
  132.         /*
  133.          *  P.S. this is a somewhat inefficient example
  134.          */
  135.         
  136.         #include <stdio.h>
  137.         
  138.         main(ac, av)
  139.         char *av[];
  140.         {
  141.            char *name;
  142.            if (ac == 1)
  143.            {
  144.               puts("Expected a file argument");
  145.               exit(1);
  146.            }
  147.            name = av[1];
  148.            if (access(name, 0) == 0)
  149.            {
  150.               puts("it exists");
  151.               if (access(name, 1) == 0)
  152.                  puts("it is executable");
  153.               if (access(name, 2) == 0)
  154.                  puts("I can write to it!");
  155.               if (access(name, 4) == 0)
  156.                  puts("and even read from it!");
  157.               else
  158.               {
  159.                  puts("Hmmm, that file does not exist");
  160.               }
  161.               return(0);
  162.            }
  163.         }
  164.  
  165. dice/acos                                                          dice/acos
  166.  
  167.     FUNCTION
  168.         take arc cosine
  169.  
  170.     LIBRARY
  171.         TBA
  172.  
  173.     SYNTAX
  174.         #include <math.h>
  175.         double a = acos(b);
  176.         double b;
  177.  
  178.     DESCRIPTION
  179.         acos returns the arc cosine of a double quantity.
  180.  
  181.     INPUTS
  182.         double b;     double floating point value
  183.  
  184.     RESULTS
  185.         double a;      result double floating point value
  186.  
  187.     SEE ALSO
  188.         asin, atan, cos, exp, fabs, log, log10, pow, sin, sqrt, tan, facos,
  189.         fasin, ...
  190.  
  191.     EXAMPLE
  192.         /*
  193.          *  compile with the math library -lm
  194.          */
  195.         #include <math.h>
  196.         #include <stdio.h>
  197.         main() 
  198.         {    
  199.            {
  200.               double a = acos(0.25);
  201.               printf("acos 0.25 = %lf\n", a); /* 1.318   */
  202.            }
  203.            {
  204.               /* less accuracy   */
  205.               float a = facos(0.25);
  206.               printf("acos 0.25 = %lf\n", (double)a);
  207.            }
  208.            return(0);
  209.         }
  210.  
  211. dice/alloca                                                      dice/alloca
  212.  
  213.     FUNCTION
  214.         allocate memory from the stack
  215.  
  216.     LIBRARY
  217.         TBA
  218.  
  219.     SYNTAX
  220.         #include <TBA.h>
  221.         void *ptr = alloca(long bytes);
  222.  
  223.     DESCRIPTION
  224.         alloca comes from the UNIX world.  It allocates memory off the stack
  225.         for use within a procedure.  The allocated memory is automatically
  226.         freed when the subroutine returns.
  227.  
  228.         :: BEGINNER'S NOTE: Do not use alloca if you can help it; alloca is
  229.         :: not easily portable across machines.
  230.  
  231.         :: NOTE: When a low stack condition arises, alloca will abort by
  232.         :: printing an error message and calling abort;  alloca does not
  233.         :: currently try to allocate dynamic memory when it runs out of stack.
  234.         :: Some implementations of alloca use alloca(0) to free allocated
  235.         :: stack. This feature is not currently implemented in DICE's alloca
  236.         :: call.
  237.  
  238.     SEE ALSO
  239.         setjmp, longjmp
  240.  
  241.     EXAMPLE
  242.         #include <alloca.h>
  243.         #include <stdio.h>
  244.         main(ac, av)
  245.         char *av[];
  246.         {
  247.            char *ptr;
  248.            if (ac == 1)
  249.            {
  250.               puts("test string");
  251.               exit(1);
  252.            }
  253.            ptr = alloca(strlen(av[1]) + 8);
  254.            sprintf(ptr, "FOO.%s", av[1]);
  255.            puts(ptr);
  256.            return(0);
  257.         }
  258.  
  259. dice/asctime                                                    dice/asctime
  260.  
  261.     FUNCTION
  262.         convert broken down time into standard text
  263.  
  264.     LIBRARY
  265.         TBA
  266.  
  267.     SYNTAX
  268.         #include <TBA.h>
  269.         char *str = asctime(ts);
  270.         const struct tm *ts;
  271.  
  272.     DESCRIPTION
  273.         asctime converts a broken down time in the tm structure to an ASCII
  274.         string and returns a pointer to that string. The time string is
  275.          formatted like this:
  276.             Mon Dec 8 01:53:33 1987\n\0
  277.         where \n stands for a newline character and \0 is terminating NULL.
  278.         The string is stored in a static buffer shared by both asctime and
  279.         ctime and so will be overwritten whenever either function is called.
  280.  
  281.     INPUTS
  282.         struct tm *ts;    pointer to a broken down time structure
  283.  
  284.     RESULTS
  285.         char *str;    pointer to static string
  286.  
  287.     SEE ALSO
  288.         time, localtime, asctime, strftime, ctime, clock
  289.  
  290.     EXAMPLE
  291.         /*
  292.          * since the string returned by asctime already has a
  293.          * newline on it we use fputs instead puts.
  294.          */
  295.         #include <stdio.h>
  296.         #include <time.h>
  297.         
  298.         main()
  299.         {
  300.            time_t t = time(NULL);
  301.            fputs(asctime(localtime(&t)), stdout);
  302.            return(0);
  303.         }
  304.  
  305. dice/assert                                                      dice/assert
  306.  
  307.     FUNCTION
  308.         assert that an expression is true,  else abort
  309.  
  310.     LIBRARY
  311.         TBA
  312.  
  313.     SYNTAX
  314.         #include <assert.h>
  315.          assert(condition);
  316.         /* MACRO */
  317.  
  318.     DESCRIPTION
  319.         assert checks the condition and if not true prints an error message
  320.         indicating the source filename and line number that the assertion
  321.         failed at, and then aborts.  The DICE version of assert generates a
  322.         single static string in assert.h for each module containing the file
  323.         name. Multiple usages of assert refer to the same physical filename
  324.         string.
  325.  
  326.     INPUTS
  327.         expression;    an expression which the macro converts into
  328.         an if(!(expression)).
  329.  
  330.     RESULTS
  331.         none
  332.  
  333.     SEE ALSO
  334.         abort
  335.  
  336.     EXAMPLE
  337.         #include <assert.h>
  338.         
  339.         main(ac, av)
  340.         int ac;
  341.         char **av;
  342.         
  343.         {
  344.            assert(ac > 1); /*  expect at least one argument! */
  345.            return(0);
  346.         }
  347.  
  348. dice/asin                                                          dice/asin
  349.  
  350.     FUNCTION
  351.         take the arc sine of a double quantity
  352.  
  353.     LIBRARY
  354.         TBA
  355.  
  356.     SYNTAX
  357.         #include <math.h>
  358.         double a = asin(b);
  359.         double b;
  360.  
  361.     DESCRIPTION
  362.         asin takes the arc sine of a floating point quantity.
  363.  
  364.     INPUTS
  365.         double b;    double floating point value
  366.  
  367.     RESULTS
  368.         double a;    result double floating point value
  369.  
  370.     SEE ALSO
  371.         acos, cos, exp, fabs, log, log10, pow, sin, sqrt, tan facos, fasin,
  372.         ...
  373.  
  374.     EXAMPLE
  375.         /*
  376.         *  compile with the math library -lm
  377.         */
  378.         #include <math.h>
  379.         #include <stdio.h>
  380.         main()
  381.         {
  382.            {
  383.               double a = asin(0.25);
  384.               printf("asin 0.25 = %lf\n", a);  /* 0.2527 */
  385.            }
  386.            {
  387.               /* less accuracy  */
  388.               float a = fasin(0.25);
  389.               printf("asin 0.25 = %lf\n", (double)a);
  390.            }
  391.            return(0);
  392.         }
  393.  
  394. dice/atan                                                          dice/atan
  395.  
  396.     FUNCTION
  397.         take arc tan of a double quantity
  398.  
  399.     LIBRARY
  400.         TBA
  401.  
  402.     SYNTAX
  403.         #include <math.h>
  404.         double a = atan(b);
  405.         double b;
  406.  
  407.     DESCRIPTION
  408.         atan takes the arc tangent of a floating point quantity.
  409.  
  410.     INPUTS
  411.         double b;    double floating point value
  412.  
  413.     RESULTS
  414.         double a;    result double floating point value
  415.  
  416.     SEE ALSO
  417.         acos, asin, cos, exp, fabs, log, log10, pow, sin, sqrt, tan facos,
  418.         fasin, ..
  419.  
  420.     EXAMPLE
  421.         /*
  422.          *  compile with the math library -lm
  423.          */
  424.         #include <math.h>
  425.         #include <stdio.h>
  426.         
  427.         main()
  428.         {
  429.            {
  430.               double a = atan(0.25);
  431.               printf("atan 0.25 = %lf\n", a);  /* 0.245   */
  432.            }
  433.            {
  434.               /*  less accuracy   */ 
  435.               float a = fatan(0.25);
  436.               printf("atan 0.25 = %lf\n", (double)a); 
  437.            }
  438.            return(0);
  439.         }
  440.  
  441. dice/atexit                                                      dice/atexit
  442.  
  443.     FUNCTION
  444.         specify routine that is automatically called on exit.
  445.  
  446.     LIBRARY
  447.         TBA
  448.  
  449.     SYNTAX
  450.         #include <stdio.h>
  451.         #include <stdlib.h>
  452.         int error = atexit(funcptr);
  453.         void (*funcptr)(void);
  454.  
  455.     DESCRIPTION
  456.         The atexit routine adds a function to the list of functions called
  457.         when the program exits.  The atexit routine is called before `stdio
  458.         and `fd's are closed down.  This exit function is called whenever the
  459.         program exits, even if `main just returns an exit code.  atexit will
  460.         return 0 on success, -1 on failure. Some systems limit the number of
  461.         `atexit functions one can add (DICE does not) so if you add more than
  462.         one you should check the return value.
  463.  
  464.     INPUTS
  465.         void (*funcptr)(void);       routine to add to exit call list, takes no
  466.         arguments and returns nothing.
  467.  
  468.     RESULTS
  469.         int error;    0 on success, -1 on failure.
  470.  
  471.     SEE ALSO
  472.         onbreak
  473.  
  474.     EXAMPLE
  475.         /*
  476.          *  Atexit is useful to free up resources that would other
  477.          *  wise not be freed up by DICE.  For example, any 
  478.          *  thing AllocMemd.  Theatexit function is called on 
  479.          *  any exit ...  return from main, call to exit, or ^C.
  480.          *
  481.          *  normally your atexit routine cannot make assumptions
  482.          *  as to what has been allocated and what has not since
  483.          *  exit can be called from anywhere in the program.
  484.          *  Things might not have been allocated yet, for example.
  485.          */
  486.         #include <stdio.h>
  487.         #include <stdlib.h>
  488.         extern void *AllocMem();
  489.         void *MemPtr;R long MemLen;
  490.         void myexit(void)
  491.         {
  492.            if (MemPtr) /*  only if it is allocated */
  493.                FreeMem(MemPtr, MemLen);
  494.            MemPtr = NULL;
  495.         }
  496.  
  497.         /*
  498.          *  here we can take a ^C anywhere... before we allocate,
  499.          *  after, or even after we free (note I am careful to set
  500.          *  MemPtr back to NULL!)
  501.          */
  502.         main()
  503.         {
  504.            short i;
  505.            atexit(myexit);
  506.            for (i = 0; i < 100; ++i)
  507.               printf("Before Alloc %d\n", i);
  508.            MemLen = 32;
  509.            MemPtr = AllocMem(MemLen, 0);
  510.            if (MemPtr == NULL)
  511.            {
  512.               puts("uh oh, AllocMem failed!");
  513.               exit(1);
  514.            }
  515.         
  516.            for (i = 0; i < 100; ++i)
  517.               printf("After Alloc %d\n", i);
  518.            FreeMem(MemPtr, MemLen);
  519.            MemPtr = NULL;
  520.            /* must do this or atexit routine thinks */
  521.            /* memory is still allocated!    */
  522.            for (i = 0; i < 100; ++i)
  523.               printf("After Free %d\n", i);
  524.            return(0);
  525.         }
  526.  
  527.         1> avail
  528.         1> testprg
  529.         ...
  530.         (you can ^C the testprg at any point)
  531.         1> avail  (no memory loss should be seen)
  532.  
  533. dice/atof                                                          dice/atof
  534.  
  535.     FUNCTION
  536.         convert string into double floating point value
  537.  
  538.     LIBRARY
  539.         TBA
  540.  
  541.     SYNTAX
  542.         #include <stdio.h>
  543.         #include <stdlib.h>
  544.         double d = atof(str);
  545.         const char *str;
  546.  
  547.     DESCRIPTION
  548.         atof converts a string into a double floating point value; it is
  549.         equivalent to calling strtod(str, NULL).  Please refer to strtod for
  550.         more information.
  551.  
  552.     INPUTS
  553.         char *str;    string, like "1.234E-4";
  554.  
  555.     RESULTS
  556.         double d;    double fp representation of string
  557.  
  558.     SEE ALSO
  559.         strtod
  560.  
  561.     EXAMPLE
  562.         TBA
  563.  
  564. dice/atoi                                                          dice/atoi
  565.  
  566.     FUNCTION
  567.         convert string into integer
  568.  
  569.     LIBRARY
  570.         TBA
  571.  
  572.     SYNTAX
  573.         #include <stdio.h>
  574.         #include <stdlib.h>
  575.         int x =atoi(str);
  576.         long y = atol(str);
  577.         const char *str;
  578.  
  579.     DESCRIPTION
  580.         atoi converts a string of a base 10 integer number into an integer. 
  581.         It skips initial white space, processes an optional negative sign
  582.         ('-'), processes digits '0' - '9', and returns the integer.  atoi is
  583.         superseded by the strtol function which can handle numbers of any
  584.         base. Please refer to the strtol manual page.
  585.  
  586.         :: NOTE: Under DICE, sizeof(int) == sizeof(long), and thus atoi and
  587.         :: atol are exactly the same.
  588.  
  589.     INPUTS
  590.         char *str;    string to convert to int
  591.  
  592.     RESULTS
  593.         int x;    integer result long y; integer result
  594.  
  595.     SEE ALSO
  596.         strtol
  597.  
  598.     EXAMPLE
  599.         #include <stdio.h>
  600.         #include <stdlib.h>
  601.         main()
  602.         {
  603.            int i = atoi("  \t\t -123");
  604.            printf("i = %d (-123?)\n", i);
  605.            return(0);
  606.         }
  607.  
  608. dice/atol                                                          dice/atol
  609.  
  610.     FUNCTION
  611.         convert string into long integer
  612.  
  613.     LIBRARY
  614.         TBA
  615.  
  616.     SYNTAX
  617.         #include <stdio.h>
  618.         #include <stdlib.h>
  619.         int x = atoi(str);
  620.         long y = atol(str);
  621.         const char *str;
  622.  
  623.         :: NOTE: Under DICE, sizeof(int) == sizeof(long), and thus atoi and
  624.         :: atol are exactly the same.
  625.  
  626.     DESCRIPTION
  627.         atol converts a string of a base 10 integer number into an integer. 
  628.         It skips initial  white space, processes an optional negative sign
  629.         ('-'), then processes digits '0' - '9', return the integer.  atol is
  630.         superseded by the strtol function which can handle numbers of any
  631.         base.
  632.  
  633.     INPUTS
  634.         char *str;    string to convert to int
  635.  
  636.     RESULTS
  637.         int x;    integer result
  638.  
  639.         long y;    integer result
  640.  
  641.     SEE ALSO
  642.         strtol
  643.  
  644.     EXAMPLE
  645.         #include <stdio.h>
  646.         #include <stdlib.h>
  647.         main()
  648.         {
  649.            int i = atoi("  \t\t -123");
  650.            printf("i = %d (-123?)\n", i);
  651.            return(0);
  652.         }
  653.  
  654. dice/__builtin_printf                                  dice/__builtin_printf
  655.  
  656.     FUNCTION
  657.         builtin printf()
  658.  
  659.     SYNTAX
  660.         none
  661.  
  662.     LIBRARY
  663.         TBA
  664.  
  665.     DESCRIPTION
  666.         __builtin_printf is used by the author when compiling the DICE source
  667.         with other commercial compilers to 'bootstrap' them.  It exists for
  668.         historical reasons only.
  669.  
  670.         :: NOTE: __builtin_printf simply calls printf and should not be used
  671.         :: normally.
  672.  
  673.     SEE ALSO
  674.         printf
  675.  
  676.     EXAMPLE
  677.         TBA
  678.  
  679. dice/bcmp                                                          dice/bcmp
  680.  
  681.     FUNCTION
  682.         compare two memory buffers (UNIX)
  683.  
  684.     LIBRARY
  685.         TBA
  686.  
  687.     SYNTAX
  688.         #include <TBA.h>
  689.         int r = bcmp(s1, s2, bytes)
  690.         void *s1;
  691.         void *s2;
  692.         size_t bytes;
  693.  
  694.     DESCRIPTION
  695.         bcmp compares two memory buffers.  A byte by byte (unsigned)
  696.         comparison is done.  When a comparison fails and the byte in s1 is
  697.         less than the byte in s2 then -1 is returned.  If the byte in s1 is
  698.         greater than the byte in s2 then 1 is returned.  If the count is
  699.         exhausted and all comparisons succeed then 0 is returned indicating
  700.         the two buffers are the same.
  701.  
  702.     INPUTS
  703.         void *s1;    pointer to first buffer
  704.  
  705.         void *s2;    pointer to second buffer
  706.  
  707.         size_t bytes;    size of each buffer
  708.  
  709.     RESULTS
  710.         int r;     -1 if buf s1 < buf s2, 0 if buf s1 == buf s2, 1 if buf s1 >
  711.         buf s2.
  712.  
  713.     SEE ALSO
  714.         cmpmem, memcmp
  715.  
  716.     EXAMPLE
  717.         #include <stdlib.h>
  718.         #include <assert.h>
  719.         main()
  720.         {
  721.            unsigned char buf1[4];
  722.            unsigned char buf2[4];
  723.            int r;
  724.            buf1[0] = 0;
  725.            buf2[0] = 0;
  726.            buf1[1] = 10;
  727.            buf2[1] = 10;
  728.            buf1[2] = 15;
  729.            buf2[2] = 15;
  730.            buf1[3] = 4;
  731.            buf2[3] = 4;
  732.            r = bcmp(buf1, buf2, 4);
  733.            assert(r == 0);
  734.            buf1[2] = 12;
  735.            r = bcmp(buf1, buf2, 4);
  736.            assert(r < 0);
  737.            buf1[2] = 200;
  738.            r = bcmp(buf1, buf2, 4);
  739.            assert(r > 0);
  740.            return(0);
  741.         }
  742.  
  743. dice/c.a                                                            dice/c.a
  744.  
  745.     FUNCTION
  746.         DICE startup module for all C programs
  747.  
  748.     LIBRARY
  749.         TBA
  750.  
  751.     SYNTAX
  752.         c.a is entered when the program segment is run.
  753.  
  754.     DESCRIPTION
  755.         DCC specifies DLIB:C.O first when linking objects into an executable.
  756.         `C.O also exists in `C.LIB but is not normally pulled since it is
  757.          already included in the link line.
  758.         `C.O does the following:
  759.  
  760.         0) Save non-scratch registers
  761.  
  762.         1) If resident, allocate space for both data & BSS and copy the
  763.         1) initialized data into the allocated space. Clear the BSS portion of
  764.         1) the data space.  If the BSS has already been allocated by the load
  765.         1) module but not cleared, clear the BSS portion of the data space.
  766.  
  767.         2) Clear the ^C signal
  768.  
  769.         3) Setup _SysBase
  770.  
  771.         4) Call all AUTOINIT  subroutines (this usually results in at least
  772.         4) the dos.library being opened).
  773.  
  774.         5) call _main (usually in c.lib as well)
  775.  
  776.         6) fall through to _exit(0)
  777.         6) Note that while c.a falls through to _exit after calling _main,
  778.         6) _main itself calls main with: exit(main(args...)); Thus, main is
  779.         6) always expected to return a valid value (i.e. not void).
  780.  
  781.         `C.O. also handles the low level exit _exit (__exit:) in the following
  782.         sequence:
  783.  
  784.         7) Call autoinit exit subroutines (this normally closes the DOS
  785.         7) library and other automatically opened libraries such as floating
  786.         7) point libraries).
  787.  
  788.         8) Free all memory allocated by the task, including the small data
  789.         8) segment & BSS space.  Note that all variables we use hereafter have
  790.         8) already been placed in registers since the dataspace is no longer
  791.         8) valid.
  792.  
  793.         9) If the _WBMsg is not NULL then: (a) Forbid() (b) ReplyMsg(_WBMsg).
  794.  
  795.         10) Restore original registers and rts (exit out of the process).
  796.  
  797.         :: NOTE:  Normally the programmer does not overide the startup object
  798.         :: file (c.o) since this is the entry point into the program.
  799.  
  800.         However, in many cases a programmer will want to overide _main, as in:
  801.  
  802.         _main(len, arg) int len; char *arg; {    ... }
  803.  
  804.         In which case he is given the length and arg pointer passed to the
  805.         program on startup. When you overide _main you cannot call any stdio
  806.         (fopen, fclose, puts, etc...), any low level IO (open, close, read,
  807.          write, etc...), or any memory allocation routines.
  808.         Normally _main will be overridden if the program makes only system
  809.         calls (such as `Open, `Close, `Read, `Write, `FindTask, etc.).
  810.         Overriding the C.LIB generally makes executables much smaller because
  811.         no extraneous stdio or low level IO routines are brought in from c.lib
  812.         . Normally you exit out of _main by calling _exit(code) (note the
  813.         underscore).
  814.  
  815.     SEE ALSO
  816.         TBA
  817.  
  818.     EXAMPLE
  819.         TBA
  820.  
  821. dice/calloc                                                      dice/calloc
  822.  
  823.     FUNCTION
  824.         allocate memory and clear
  825.  
  826.     LIBRARY
  827.         TBA
  828.  
  829.     SYNTAX
  830.         #include <TBA.h>
  831.         void *ptr = calloc(objsize, numobjs)
  832.         size_t objsize;
  833.         size_t numobjs;
  834.  
  835.     DESCRIPTION
  836.         Numobjs objects each objsize in size are allocated contiguously and a
  837.         pointer to the first object is returned.  The memory is cleared to 0. 
  838.         Effectively this is equivalent to malloc(objsize * numobjs), and then
  839.         setmem(ptr, objsize * numobjs, 0) . calloc returns NULL if the memory
  840.         cannot be allocated.
  841.  
  842.     INPUTS
  843.         size_t objsize;    size of each object
  844.  
  845.         size_t numobjs;    number of objects to allocate
  846.  
  847.     RESULTS
  848.         void *ptr;    pointer to first object
  849.  
  850.     SEE ALSO
  851.         malloc, strdup
  852.  
  853.     EXAMPLE
  854.         /*
  855.          *  allocate 16 objects and fill with junk
  856.          */
  857.         #include <stdlib.h>
  858.         #include <assert.h>
  859.         typedef struct
  860.         {
  861.            long a, b, c;
  862.         }
  863.         Junk;
  864.         main()
  865.         {
  866.            Junk *jp;
  867.            jp = calloc(sizeof(Junk), 16);
  868.            assert(jp);
  869.            {       
  870.               Junk *tj = jp;
  871.               short i;
  872.               for (i = 0; i < 16; ++i, ++tj)
  873.               {
  874.                  tj->a = 1;
  875.                  tj->b = 2;
  876.                  tj->c = 3;
  877.               }
  878.            }
  879.         free(jp);
  880.         return(0);
  881.         }
  882.  
  883. dice/chdir                                                        dice/chdir
  884.  
  885.     FUNCTION
  886.         change current directory
  887.  
  888.     LIBRARY
  889.         TBA
  890.  
  891.     SYNTAX
  892.         #include <TBA.h>
  893.         int r = chdir(path);
  894.         const char *path;
  895.  
  896.     DESCRIPTION
  897.         chdir changes the current directory to the specified path, returning 0
  898.         on success and -1 on failure.
  899.  
  900.         :: NOTE:  When a program exits, the original directory will be
  901.         :: restored.
  902.  
  903.     INPUTS
  904.         char *path;    path to chdir into
  905.  
  906.     RESULTS
  907.         int r;    return value, 0 if ok, -1 if error
  908.  
  909.     SEE ALSO
  910.         getcwd
  911.  
  912.     EXAMPLE
  913.         #include <stdio.h>
  914.         char buf[512];
  915.         main(ac, av)
  916.         int ac;
  917.         char *av[];
  918.         {
  919.            getcwd(buf, sizeof(buf));
  920.            if (chdir("RAM:"))
  921.            {
  922.               puts("Couldn't chdir into RAM:");
  923.               exit(1);
  924.            }
  925.            FILE *fp;
  926.            if (fp = fopen("yy", "w"))
  927.            {
  928.               fclose(fp);
  929.               puts("created file yy in RAM:");
  930.            }
  931.            if (chdir(buf))
  932.            {
  933.               printf("Unable to chdir back into %s\n", buf);
  934.            }
  935.            return(0);
  936.         }
  937.  
  938. dice/chkabort                                                  dice/chkabort
  939.  
  940.     FUNCTION
  941.         Check for ^C and take the appropriate action
  942.  
  943.     LIBRARY
  944.         TBA
  945.  
  946.     SYNTAX
  947.         #include <TBA.h>
  948.         (void) chkabort(void);
  949.  
  950.     DESCRIPTION
  951.         chkabort checks for a ^C and takes the appropriate action.  If the
  952.         appropriate action is to exit then this routine does not return. 
  953.         Stdio and other routines will call chkabort at various points.  The
  954.         action taken by ^C may be set by the signal or onbreak calls.
  955.  
  956.     SEE ALSO
  957.         onbreak, atexit, signal
  958.  
  959.     EXAMPLE
  960.         /*
  961.          *  wait for somebody to hit ^C (note that this is very
  962.          *  wasteful of CPU and thus isn't a real good example).
  963.          */
  964.         main()
  965.         {
  966.            int i;
  967.            for (i = 0; i < 10000000; ++i)
  968.               chkabort();
  969.            return(0);
  970.         }
  971.  
  972. dice/clearerr                                                  dice/clearerr
  973.  
  974.     FUNCTION
  975.         Clear error associated with a file pointer
  976.  
  977.     LIBRARY
  978.         TBA
  979.  
  980.     SYNTAX
  981.         #include <stdio.h>
  982.         void clearerr(fp);
  983.         (MACRO) FILE *fp;
  984.  
  985.     DESCRIPTION
  986.         The clearerr macro clears both the EOF flag and the ERROR flag
  987.         associated with a file pointer. When an ERROR occurs on a file pointer
  988.         further fread, fwrite, and some other calls will not work until the
  989.         ERROR indicator is cleared.
  990.  
  991.         :: NOTE: Refer to the file_pointer manual page for general
  992.         :: information.
  993.  
  994.     INPUTS
  995.         FILE *fp;     file pointer to clear the error on.
  996.  
  997.     RESULTS
  998.         none;     the error and EOF indicators are cleared
  999.  
  1000.     SEE ALSO
  1001.         feof, ferror, rewind, fseek
  1002.  
  1003.     EXAMPLE
  1004.         TBA
  1005.  
  1006. dice/clock                                                        dice/clock
  1007.  
  1008.     FUNCTION
  1009.         return system clock value
  1010.  
  1011.     LIBRARY
  1012.         TBA
  1013.  
  1014.     SYNTAX
  1015.         #include <TBA.h>
  1016.         clock_t clk = clock(void);
  1017.  
  1018.     DESCRIPTION
  1019.         clock returns the system clock in ticks.  To obtain seconds from ticks
  1020.         divide the returned value by CLK_TCK in <time.h>.
  1021.  
  1022.     INPUTS
  1023.         none
  1024.  
  1025.     RESULTS
  1026.         clock_t clk;     system clock time value
  1027.  
  1028.     SEE ALSO
  1029.         time, localtime, asctime, strftime, ctime, clock
  1030.  
  1031.     EXAMPLE
  1032.         #include <stdio.h>
  1033.         #include <time.h>
  1034.         
  1035.         main()
  1036.         {
  1037.            clock_t clk = clock();
  1038.            long i;
  1039.            clk = clk + CLK_TCK;
  1040.            for (i = 0; clk - clock() > 0; ++i);
  1041.            printf("The FOR loop calling clock() took %d loops in
  1042.                    one second\n", i);
  1043.            return(0);
  1044.         }
  1045.  
  1046. dice/close                                                        dice/close
  1047.  
  1048.     FUNCTION
  1049.         close a file descriptor
  1050.  
  1051.     LIBRARY
  1052.         TBA
  1053.  
  1054.     SYNTAX
  1055.         #include <TBA.h>
  1056.         int r = close(fd);
  1057.         int fd;
  1058.  
  1059.     DESCRIPTION
  1060.         close closes a file descriptor.  If an error occurs or the descriptor
  1061.         is invalid, a non-zero return code will result and `errno will be set
  1062.         to the appropriate error condition.
  1063.  
  1064.         :: NOTE:  Refer to the file_descriptor manual page for general
  1065.         :: information. Unlike file pointers and file handles, the file
  1066.         :: descriptor is checked for validity and if  illegal, an error will
  1067.         :: be returned.
  1068.  
  1069.     INPUTS
  1070.         int fd;     file descriptor to close, the file descriptor becomes invalid
  1071.         after this call
  1072.  
  1073.     RESULTS
  1074.         int r;     return value, 0 == ok, non-zero == error
  1075.  
  1076.     SEE ALSO
  1077.         creat, fcntl, fdtofh, ioctl, isatty, lseek, mkdir, open, read, rmdir,
  1078.         unlink, write
  1079.  
  1080.         #include <fcntl.h>
  1081.         
  1082.         main()
  1083.         {
  1084.            int fd;
  1085.            fd  = open("T:xx", O_WRONLY|O_CREAT|O_TRUNC);
  1086.            if (fd >= 0)
  1087.            {
  1088.               puts("created empty file T:xx");
  1089.               close(fd);
  1090.            }
  1091.            else
  1092.            {
  1093.               puts("unable to create T:xx");
  1094.            }
  1095.            return(0);
  1096.         }
  1097.  
  1098. dice/cmpmem                                                      dice/cmpmem
  1099.  
  1100.     FUNCTION
  1101.         compare two memory buffers
  1102.  
  1103.     LIBRARY
  1104.         TBA
  1105.  
  1106.     SYNTAX
  1107.         #include <TBA.h>
  1108.         int r = cmpmem(s1, s2, bytes)
  1109.         void *s1;
  1110.         void *s2;
  1111.         size_t bytes;
  1112.  
  1113.     DESCRIPTION
  1114.         Like bcmp, this function compares two memory buffers.  A byte by byte
  1115.         (unsigned) comparison is done.  When a comparison fails and the byte
  1116.         in s1 is less than the byte in s2 then -1 is returned. If the byte in
  1117.         s1 is greater than the byte in s2 then 1 is returned. If the count is
  1118.         exhausted and all comparisons succeed then 0 is returned indicating
  1119.         the two buffers are the same.
  1120.  
  1121.     INPUTS
  1122.         void *s1;    pointer to first buffer
  1123.  
  1124.         void *s2;    pointer to second buffer
  1125.  
  1126.         size_t bytes;    size of each buffer
  1127.  
  1128.     RESULTS
  1129.         int r;    -1 if buf s1 < buf s2, 0 if buf s1 == buf s2, 1 if buf s1 > buf
  1130.         s2.
  1131.  
  1132.     SEE ALSO
  1133.         bcmp, memcmp
  1134.  
  1135.     EXAMPLE
  1136.         #include <stdlib.h>
  1137.         #include <assert.h>
  1138.         
  1139.         main()
  1140.         {
  1141.            unsigned char buf1[4];
  1142.            unsigned char buf2[4];
  1143.            int r;
  1144.            buf1[0] = 0;
  1145.            buf2[0] = 0;
  1146.            buf1[1] = 10;
  1147.            buf2[1] = 10;
  1148.            buf1[2] = 15;
  1149.            buf2[2] = 15;
  1150.            buf1[3] = 4;
  1151.            buf2[3] = 4;
  1152.            r = cmpmem(buf1, buf2, 4);
  1153.            assert(r == 0);
  1154.            buf1[2] = 12;
  1155.            r = cmpmem(buf1, buf2, 4);
  1156.            assert(r < 0);
  1157.            buf1[2] = 200;
  1158.            r = cmpmem(buf1, buf2, 4);
  1159.            assert(r > 0);
  1160.            return(0);
  1161.         }
  1162.  
  1163. dice/cos                                                            dice/cos
  1164.  
  1165.     FUNCTION
  1166.         return cosine of a double quantity
  1167.  
  1168.     LIBRARY
  1169.         TBA
  1170.  
  1171.     SYNTAX
  1172.         #include <math.h>
  1173.         double a = cos(b);
  1174.         double b;
  1175.  
  1176.     DESCRIPTION
  1177.         cos returns the cosine of a floating point quantity.
  1178.  
  1179.     INPUTS
  1180.         double b;     double floating point value
  1181.  
  1182.     RESULTS
  1183.         double a;      result double floating point value
  1184.  
  1185.     SEE ALSO
  1186.         acos, asin, atan, exp, fabs, log, log10, pow, sin, sqrt, tan facos,
  1187.         fasin, fcos, ...
  1188.  
  1189.     EXAMPLE
  1190.         /*
  1191.          *  compile with the math library -lm
  1192.          */
  1193.         #include <math.h>
  1194.         #include <stdio.h>
  1195.         
  1196.         main()
  1197.         {
  1198.            {
  1199.               double a = cos(0.25);
  1200.               printf("cos 0.25 = %lf\n", a);  /* 0.9689 */
  1201.            }
  1202.            {
  1203.               /*  less accuracy   */
  1204.               float a = fcos(0.25);
  1205.               printf("cos 0.25 = %lf\n", (double)a);
  1206.            }
  1207.            return(0);
  1208.         }
  1209.  
  1210. dice/creat                                                        dice/creat
  1211.  
  1212.     FUNCTION
  1213.         create a file
  1214.  
  1215.     LIBRARY
  1216.         TBA
  1217.  
  1218.     SYNTAX
  1219.         #include <TBA.h>
  1220.         int fd = creat(file);
  1221.         char *file;
  1222.  
  1223.     DESCRIPTION
  1224.         creat creates a new file and returns a file descriptor for it. This
  1225.         call is equivalent to open(file,O_CREAT|O_TRUNC|O_RDWR); this is an
  1226.         obsolete function and should not be used.
  1227.  
  1228.         :: NOTE: Refer to the file_descriptor manual page for general
  1229.         :: information Unlike file pointers and file handles, the file
  1230.         :: descriptor is checked for validity and will simply return an error
  1231.         :: if illegal.
  1232.  
  1233.     INPUTS
  1234.         char *file;     nul terminated string that is the filename
  1235.  
  1236.     RESULTS
  1237.         int  fd;     file descriptor if >= 0, error if < 0.
  1238.  
  1239.     SEE ALSO
  1240.         close, fcntl, fdtofh, ioctl, isatty, lseek, mkdir, open, read, rmdir,
  1241.         unlink, write
  1242.  
  1243.     EXAMPLE
  1244.         #include <fcntl.h>
  1245.         main()
  1246.         {
  1247.            int fd;
  1248.            fd = creat("T:xx");
  1249.            if (fd >= 0)
  1250.            {
  1251.               puts("created empty file T:xx");
  1252.               close(fd);
  1253.            }
  1254.            else
  1255.            {
  1256.               puts("unable to create T:xx");
  1257.            }
  1258.            return(0);
  1259.         }
  1260.  
  1261. dice/ctime                                                        dice/ctime
  1262.  
  1263.     FUNCTION
  1264.         convert time into standard text
  1265.  
  1266.     LIBRARY
  1267.         TBA
  1268.  
  1269.     SYNTAX
  1270.         #include <TBA.h>
  1271.         char *str = ctime(&t); time_t t;
  1272.  
  1273.     DESCRIPTION
  1274.         ctime converts a time pointer into ASCII text using the following
  1275.          format:
  1276.             Sun Dec 8 01:53:33 1987\n\0
  1277.         where \n stands for a newline character and \0 is terminating nul.
  1278.         The string is stored in a static buffer shared by both asctime and
  1279.         ctime and so will be overwritten whenever either function is called.
  1280.  
  1281.     INPUTS
  1282.         time_t *t;      pointer to a time_t value
  1283.  
  1284.      RESULTS
  1285.         char *str;     pointer to static string
  1286.  
  1287.     SEE ALSO
  1288.         time, localtime, asctime, strftime, ctime, clock
  1289.  
  1290.     EXAMPLE
  1291.         /*
  1292.          *  since the string returned by ctime already has a newline
  1293.          *  on it we use fputs instead puts.
  1294.          */
  1295.         #include <stdio.h>
  1296.         #include <time.h>
  1297.         
  1298.         main()
  1299.         {
  1300.            time_t t = time(NULL);
  1301.            fputs(ctime(&t), stdout);
  1302.            return(0);
  1303.         }
  1304.  
  1305. dice/dir                                                            dice/dir
  1306.  
  1307.     FUNCTION
  1308.         display directory of scanning routines
  1309.  
  1310.     LIBRARY
  1311.         TBA
  1312.  
  1313.     SYNTAX
  1314.         #include <sys/dir.h>
  1315.         DIR *dirhan = opendir(path);
  1316.         struct direct *entry = readdir(dirhan);
  1317.         (void) rewinddir(dirhan);
  1318.         void
  1319.         closedir(dirhan);
  1320.         const char *path;
  1321.         DIR *dirhan;
  1322.  
  1323.     DESCRIPTION
  1324.         These are UNIX compatible directory scanning calls.  After opening a
  1325.         directory with opendir, you may scan it with successive calls to
  1326.         readdir until NULL is returned, then either rewinddir it for a rescan,
  1327.         or closedir it when done.  The DIR structure is private to the
  1328.         library.  Valid fields within struct direct are d_name (the file
  1329.         name), and d_namlen (the length of the file name, not usually needed).
  1330.         You can chdir into the directory and stat each entry to obtain
  1331.         additional information.  Note that while the UNIX directory scanning
  1332.         routines will not be as efficient as the Amiga directory scanning
  1333.         routines, the UNIX directory scanning routines are portable.
  1334.  
  1335.         :: NOTE: Unlike the Amiga directory scanning routines that use `Locks,
  1336.         :: these calls will automatically deallocate resources if the program
  1337.         :: terminates. rewinddir's prototype returns an int.  This is for
  1338.         :: internal use only.  You should never use rewinddir's return value
  1339.         :: yourself.
  1340.  
  1341.     INPUTS
  1342.         TBA
  1343.  
  1344.     RESULTS
  1345.         TBA
  1346.  
  1347.     SEE ALSO
  1348.         chdir
  1349.  
  1350.     EXAMPLE
  1351.         #include <stdio.h>
  1352.         #include <sys/dir.h>
  1353.         main(ac, av)
  1354.         int ac;
  1355.         char *av[];
  1356.         {
  1357.            DIR *dir;
  1358.            if (ac == 1)
  1359.            {
  1360.               puts("test dir");
  1361.               exit(1);
  1362.            }
  1363.            if (dir = opendir(av[1]))
  1364.            {
  1365.               struct direct *entry;
  1366.               while (entry = readdir(dir))
  1367.               {
  1368.                  printf("%s\n", entry->d_name);
  1369.               }
  1370.               closedir(dir);
  1371.            }
  1372.            return(0);
  1373.         }
  1374.  
  1375. dice/_divs                                                        dice/_divs
  1376.  
  1377.     FUNCTION
  1378.         Signed long divide
  1379.  
  1380.     LIBRARY
  1381.         TBA
  1382.  
  1383.     SYNTAX
  1384.         TBA
  1385.  
  1386.     DESCRIPTION
  1387.         DICE uses this assembly level function whenever it needs to do long
  1388.         division.  divs is not callable from C.
  1389.  
  1390.     INPUTS
  1391.         D0 = 32 bit signed integer
  1392.  
  1393.         D1 = 32 bit signed integer
  1394.  
  1395.     RESULTS
  1396.         D0 = D0 / D1
  1397.  
  1398.     SEE ALSO
  1399.         _divu, _mods, _modu, _muls, _mulu
  1400.  
  1401.     EXAMPLE
  1402.         TBA
  1403.  
  1404. dice/_divu                                                        dice/_divu
  1405.  
  1406.     FUNCTION
  1407.         unsigned long divide
  1408.  
  1409.     LIBRARY
  1410.         TBA
  1411.  
  1412.     SYNTAX
  1413.         TBA
  1414.  
  1415.     DESCRIPTION
  1416.         DICE uses this function whenever it needs to do unsigned long
  1417.         division.  As with _divs, this function is not callable from C.
  1418.  
  1419.     INPUTS
  1420.         D0 = 32 bit unsigned integer
  1421.  
  1422.         D1 = 32 bit unsigned integer
  1423.  
  1424.     RESULTS
  1425.         D0 = D0 / D1
  1426.  
  1427.     SEE ALSO
  1428.         _divs, _mods, _modu, _muls, _mulu
  1429.  
  1430.     EXAMPLE
  1431.         TBA
  1432.  
  1433. dice/_DOSBase                                                  dice/_DOSBase
  1434.  
  1435.     FUNCTION
  1436.         auto-open DOS Library Base
  1437.  
  1438.     LIBRARY
  1439.         TBA
  1440.  
  1441.     DESCRIPTION
  1442.         The _DOSBase base variable is referenced (i.e. extern) but not
  1443.         declared,  _DOSBase will be automatically declared in the doslib
  1444.         module of auto.lib. Additionally, auto.lib adds routines to the
  1445.         autoinit and autoexit sequences called by c.a that automatically opens
  1446.         "dos.library" before _main and closes it after _exit.  If the
  1447.         auto-open fails the program will be aborted before _main is ever
  1448.         called.  Before the autoexit routine closes the library it checks to
  1449.         see if the base variable is NULL if so, skips trying to close the
  1450.         library.
  1451.  
  1452.         :: NOTE: _DOSBase is normally openned this way for most programs since
  1453.         :: parts of c.a are normally references that make DOS calls.  In fact,
  1454.         :: all programs which use the main entry point after c.lib's _main
  1455.         :: entry point refer to DOS.
  1456.  
  1457.     EXAMPLE
  1458.         TBA
  1459.  
  1460. dice/exec_dcc                                                  dice/exec_dcc
  1461.  
  1462.     FUNCTION
  1463.         Call DICE executable
  1464.  
  1465.     LIBRARY
  1466.         TBA
  1467.  
  1468.     SYNTAX
  1469.         TBA
  1470.  
  1471.     DESCRIPTION
  1472.         exec_dcc calls a DICE executable.
  1473.  
  1474.         || WARNING!  DO NOT EVER USE THIS FUNCTION YOURSELF.  This is an
  1475.         || internal DICE function used by DCC and is subject to change without
  1476.         || notice.  exec_dcc can easily break under new versions of the
  1477.         || operating system, and special care is taken by DCC when using it.
  1478.         || The 2.0 version of the Amiga operating system has calls that will
  1479.         || properly accomplish this operation.
  1480.  
  1481.     INPUTS
  1482.         TBA
  1483.  
  1484.     RESULTS
  1485.         TBA
  1486.  
  1487.     SEE ALSO
  1488.         _ExecSeg
  1489.  
  1490.     EXAMPLE
  1491.         TBA
  1492.  
  1493. dice/_ExecSeg                                                  dice/_ExecSeg
  1494.  
  1495.     FUNCTION
  1496.         Call a segment
  1497.  
  1498.     LIBRARY
  1499.         TBA
  1500.  
  1501.     SYNTAX
  1502.         TBA
  1503.  
  1504.     DESCRIPTION
  1505.         DO NOT EVER USE THIS FUNCTION.  This is an internal DICE function used
  1506.         by DCC and is subject to change without notice.  This function can
  1507.         easily break under new versions of the OS and special care is taken by
  1508.         DCC when using it. The 2.0 version of the Amiga operating system has
  1509.         calls that will properly accomplish this operation.
  1510.  
  1511.     INPUTS
  1512.         TBA
  1513.  
  1514.     RESULTS
  1515.         TBA
  1516.  
  1517.     SEE ALSO
  1518.         exec_dcc
  1519.  
  1520.     EXAMPLE
  1521.         TBA
  1522.  
  1523. dice/exit                                                          dice/exit
  1524.  
  1525.     FUNCTION
  1526.         Exit from a program 'nicely'
  1527.  
  1528.     LIBRARY
  1529.         TBA
  1530.  
  1531.     SYNTAX
  1532.         #include <TBA.h>
  1533.         (void) exit(code)
  1534.  
  1535.     LIBRARY
  1536.         TBA
  1537.  
  1538.     DESCRIPTION
  1539.         exit exits the program and returns the specified exit code. Normally
  1540.         you pass 0 to indicate no errors, and a positive number to indicate a
  1541.         program error to the parent.  exit closes all stdio file pointers, low
  1542.         level file descriptors, perhaps a few other things, and then finally
  1543.         calls _exit with the code. If you use main you should call exit to
  1544.         exit the program or return an error code from main.  If you use the
  1545.         _main entry point (only for programmers dead set on optimizing
  1546.         executable size and using only system library calls) you should use
  1547.         the _exit exit point.
  1548.  
  1549.     INPUTS
  1550.         TBA
  1551.  
  1552.     RESULTS
  1553.         TBA
  1554.  
  1555.     SEE ALSO
  1556.         main, _main, _exit
  1557.  
  1558.     EXAMPLE
  1559.         main(ac, av)
  1560.         char *av[];
  1561.         {
  1562.            if (ac <= 1)
  1563.            {
  1564.               puts("I expected an argument, you idiot!");
  1565.               exit(1);
  1566.            }
  1567.            puts("thanks for the argument!");
  1568.            exit(0);
  1569.         }
  1570.  
  1571. dice/_exit                                                        dice/_exit
  1572.  
  1573.     FUNCTION
  1574.         exit from a program without bother to release resources
  1575.  
  1576.     LIBRARY
  1577.         TBA
  1578.  
  1579.     SYNTAX
  1580.         #include <TBA.h>
  1581.         (void) _exit(code)
  1582.         int code;
  1583.  
  1584.     DESCRIPTION
  1585.         _exit exits from a program and returns the specified exit code.
  1586.         Normally you pass 0 to indicate no errors, a positive number to
  1587.         indicate a program error to the parent.  Note that since auto-init
  1588.         opened libraries are closed in the startup module (c.o), automatically
  1589.         opened libraries will be automatically closed for you.  However, any
  1590.         libraries you manually declare the library base variable for and
  1591.         manually open must be closed by you.  You should only call _exit if
  1592.         you used the _main entry point (instead of the usual main), and then
  1593.         only after releasing all resources (such as file handles opened with
  1594.         open).
  1595.  
  1596.     INPUTS
  1597.         TBA
  1598.  
  1599.     RESULTS
  1600.         TBA
  1601.  
  1602.     SEE ALSO
  1603.         main, _main, exit
  1604.  
  1605.     EXAMPLE
  1606.         /*
  1607.          *  This program comes to approximately a 552 byte
  1608.          *  executable
  1609.          */
  1610.         _main()
  1611.         {
  1612.            Write(Output(), "OW!\n", 4);
  1613.            _exit(1);
  1614.         }
  1615.  
  1616. dice/exp                                                            dice/exp
  1617.  
  1618.     FUNCTION
  1619.         return e to the power of the double quantity
  1620.  
  1621.     LIBRARY
  1622.         TBA
  1623.  
  1624.     SYNTAX
  1625.         #include <math.h>
  1626.         double a = exp(b);
  1627.         double b;
  1628.  
  1629.     DESCRIPTION
  1630.         exp returns e to the power of the floating point quantity.
  1631.  
  1632.     INPUTS
  1633.         double b;     double floating point value
  1634.  
  1635.     RESULTS
  1636.         double a;     result double floating point value
  1637.  
  1638.     SEE ALSO
  1639.         acos, asin, atan, cos, fabs, log, log10, pow, sin,  sqrt, tan facos,
  1640.         fasin, ...
  1641.  
  1642.     EXAMPLE
  1643.         /*
  1644.          *  compile with the math library -lm
  1645.          */
  1646.         #include <math.h>
  1647.         #include <stdio.h>
  1648.         main()
  1649.         {
  1650.         {
  1651.  
  1652.               double a = exp(0.25);
  1653.               printf("exp 0.25 = %lf\n", a); /* 1.284 */
  1654.            }
  1655.         {
  1656.  
  1657.               /*  less accuracy   */
  1658.               float a = fexp(0.25);
  1659.               printf("exp 0.25 = %lf\n", (double)a);
  1660.            } 
  1661.            return(0);
  1662.         }
  1663.  
  1664. dice/expand_args                                            dice/expand_args
  1665.  
  1666.     FUNCTION
  1667.         expand command line argument wildcards
  1668.  
  1669.     LIBRARY
  1670.         TBA
  1671.  
  1672.     SYNTAX
  1673.         #include <TBA.h>
  1674.         int error = expand_args(xac, xav, &ac, &av);
  1675.         int xac;
  1676.         const char **xav;
  1677.         int ac;
  1678.         char **av;
  1679.  
  1680.     DESCRIPTION
  1681.         expand_args takes an argc/argv list and expands any wildcard arguments
  1682.         by scanning the appropriate directory.  It  malloc's however much
  1683.         memory it needs to create the new list and ignores xav[0] (that is, it
  1684.         just copies it to the returned av[0] without doing a wildcard
  1685.         expansion). expand_args fills in the ac and av variables with its own
  1686.         malloc'd version of the argument list, now completely expanded.  There
  1687.         is no limit to the number of files that may be in this result list
  1688.         (you could conceivably have thousands).  expand_args may be used to
  1689.         expand arbitrary AmigaDOS wildcards and is not limited to an anchored
  1690.         search.  For example, you could specify:   sys:#?/#? in which case a
  1691.         list of a second level files/dirs will be generated. In the above
  1692.         case, expand_args scans sys, then scans any sub directories found in
  1693.         sys.  Generic AmigaDOS wildcarding is used and incredibly complex
  1694.         wildcards may be specified.  Please note, however, that any wildcard
  1695.         elements containing #? in combination with other elements (such as
  1696.         (a|b|c)) will cause huge amounts of stack to be used and also quite a
  1697.         bit of memory during the scan. expand_args limits itself to 4K of
  1698.         stack before giving up. Any program that uses expand_args should be
  1699.         run with at least 8K of stack.
  1700.  
  1701.     INPUTS
  1702.         int  xac;     original argc
  1703.  
  1704.         char **xav;     original argv
  1705.  
  1706.         int  *ac;     pointer to new argc
  1707.  
  1708.         char ***av;     pointer to new argv
  1709.  
  1710.     RESULTS
  1711.         int error;     0 if all went well, non-zero otherwise
  1712.  
  1713.     SEE ALSO
  1714.         TBA
  1715.  
  1716.     EXAMPLE
  1717.         #include <stdio.h>
  1718.         main(xac, xav)
  1719.         int xac;
  1720.         char **xav;
  1721.         {
  1722.            int ac;
  1723.            char **av;
  1724.            short i;
  1725.            int error = expand_args(xac, xav, &ac, &av);
  1726.            for (i = 1; i < ac; ++i)
  1727.            {
  1728.               printf("%s\n", av[i]);
  1729.            }
  1730.         }
  1731.  
  1732. dice/fabs                                                          dice/fabs
  1733.  
  1734.     FUNCTION
  1735.         return the absolute value of a double quantity
  1736.  
  1737.     LIBRARY
  1738.         TBA
  1739.  
  1740.     SYNTAX
  1741.         #include <math.h>
  1742.         double a = fabs(b);
  1743.         double b;
  1744.  
  1745.     DESCRIPTION
  1746.         fabs returns the absolute value of a floating point quantity.
  1747.  
  1748.     INPUTS
  1749.         float d;     float floating point value
  1750.  
  1751.     RESULTS
  1752.         int arg;     control argument
  1753.  
  1754.         int r;      result, error if less than 0.
  1755.  
  1756.     SEE ALSO
  1757.     EXAMPLE
  1758.         /*
  1759.          *  compile with the math library -lm
  1760.          */
  1761.         #include <math.h>
  1762.         #include <stdio.h>
  1763.         main()
  1764.         {
  1765.            {
  1766.               double a = fabs(-0.25);
  1767.               printf("fabs -0.25 = %lf\n", a); /*  0.25  */
  1768.            }
  1769.            {
  1770.               /*  less accuracy   */
  1771.               float a = ffabs(-0.25);
  1772.               printf("fabs -0.25 = %lf\n", (double)a);
  1773.            }
  1774.            return(0);
  1775.         }
  1776.  
  1777. dice/facos                                                        dice/facos
  1778.  
  1779.     FUNCTON
  1780.         float arc cosine
  1781.  
  1782.     LIBRARY
  1783.         TBA
  1784.  
  1785.     SYNTAX
  1786.         #include <math.h>
  1787.         float  c = facos(d);
  1788.         float  d;
  1789.  
  1790.     DESCRIPTION
  1791.         facos returns the arc cosine of a floating point quantity.
  1792.  
  1793.     INPUTS
  1794.         float d;       float floating point value
  1795.  
  1796.     RESULTS
  1797.         result float;    floating point value
  1798.  
  1799.     SEE ALSO
  1800.         acos, asin, atan, cos, exp, fabs, log, log10, pow, sin, sqrt, tan,
  1801.         fasin, ...
  1802.  
  1803.     EXAMPLE
  1804.         /*
  1805.          *  compile with the math library -lm */
  1806.         #include <math.h>
  1807.         #include <stdio.h>
  1808.         main() 
  1809.         {    
  1810.            {
  1811.                double a = acos(0.25);
  1812.                printf("acos 0.25 = %lf\n", a); /* 1.318   */
  1813.            }
  1814.            {
  1815.                /* less accuracy   */
  1816.                float a = facos(0.25);
  1817.                printf("acos 0.25 = %lf\n", (double)a);
  1818.            }
  1819.            return(0);
  1820.         }
  1821.  
  1822. dice/fasin                                                        dice/fasin
  1823.  
  1824.     FUNCTION
  1825.         return arc sine of a float quantity
  1826.  
  1827.     LIBRARY
  1828.         TBA
  1829.  
  1830.     SYNTAX
  1831.         #include <math.h>
  1832.         float  c = fasin(d);
  1833.         float  d;
  1834.  
  1835.     DESCRIPTION
  1836.         fasin returns the arc sine of a floating point quantity.
  1837.  
  1838.     INPUTS
  1839.         float d;     float floating point value
  1840.  
  1841.     RESULTS
  1842.         float c;     result float loating point value
  1843.  
  1844.     SEE ALSO
  1845.         acos, asin, atan, cos, exp, fabs, log, log10, pow, sin, sqrt, tan
  1846.         facos, ...
  1847.  
  1848.     EXAMPLE
  1849.         /*
  1850.          *  compile with the math library -lm
  1851.          */
  1852.         #include <math.h>
  1853.         #include <stdio.h>
  1854.         
  1855.         main()
  1856.         {
  1857.            {
  1858.               double a = asin(0.25);
  1859.               printf("asin 0.25 = %lf\n", a);  /* 0.2527 */
  1860.            }
  1861.            {
  1862.               /*  less accuracy */
  1863.               float a = fasin(0.25);
  1864.               printf("asin 0.25 =  %lf\n", (double)a);
  1865.            }
  1866.            return(0);
  1867.         }
  1868.  
  1869. dice/fatan                                                        dice/fatan
  1870.  
  1871.     FUNCTION
  1872.         return arc tan of a float quantity
  1873.  
  1874.     LIBRARY
  1875.         TBA
  1876.  
  1877.     SYNTAX
  1878.         #include <math.h>
  1879.         float  c = fatan(d); float  d;
  1880.  
  1881.     DESCRIPTION
  1882.         fatan returns the arc tan of a floating point quantity.
  1883.  
  1884.     INPUTS
  1885.         float d;     float floating point value
  1886.  
  1887.     RESULTS
  1888.         float c;     result float floating point value
  1889.  
  1890.     SEE ALSO
  1891.         acos, asin, atan, cos, exp, fabs, log, log10, pow, sin, sqrt, tan
  1892.         facos, fasin, ...
  1893.  
  1894.     EXAMPLE
  1895.         /*
  1896.          *  compile with the math library -lm
  1897.          */
  1898.         #include <math.h>
  1899.         #include <stdio.h>
  1900.         main()
  1901.         {
  1902.            {
  1903.               double a = atan(0.25);
  1904.               printf("atan 0.25 = %lf\n", a);  /* 0.245   */
  1905.            }
  1906.            {
  1907.               /* less accuracy   */ 
  1908.               float a = fatan(0.25);
  1909.               printf("atan 0.25 = %lf\n", (double)a); 
  1910.            }
  1911.            return(0);
  1912.         }
  1913.  
  1914. dice/fclose                                                      dice/fclose
  1915.  
  1916.     FUNCTION
  1917.         close a file pointer
  1918.  
  1919.     LIBRARY
  1920.         TBA
  1921.  
  1922.     SYNTAX
  1923.         #include <stdio.h>
  1924.         int error = fclose(fp);
  1925.         FILE     *fp;
  1926.  
  1927.     DESCRIPTION
  1928.         fclose flushes any data remaining in the file pointer's output buffer
  1929.         to the file and then closes the file. The file pointer is no longer
  1930.         valid. fclose returns any error condition that occured while it was
  1931.         flushing the buffered data to the file.  The file is closed even if an
  1932.         error occured.
  1933.  
  1934.         :: NOTE: You can fclose(stdin), fclose(stdout), and fclose(stderr) to
  1935.         :: save space or detach your process from the console (i.e. allow the
  1936.         :: console window to be closed).
  1937.  
  1938.         || WARNING: If you fclose stdin, stdout, and stderr with the intention
  1939.         || of removing all references to the console window, you must put a
  1940.         || NULL in your processes pr_ConsoleTask field. Otherwise, the console
  1941.         || window will be able to close, but your process will still have a
  1942.         || reference to the now non-existent window.  Refer to the
  1943.         || file_pointer manual page for general information
  1944.  
  1945.     INPUTS
  1946.         FILE *F;     file pointer
  1947.  
  1948.     RESULTS
  1949.         int error;     error on fclose, or 0 if none
  1950.  
  1951.     SEE ALSO
  1952.         fopen, fread, fwrite, fgets, fputs
  1953.  
  1954.     EXAMPLE
  1955.         TBA
  1956.  
  1957. dice/fcntl                                                        dice/fcntl
  1958.  
  1959.     FUNCTION
  1960.         file control on a file
  1961.  
  1962.     LIBRARY
  1963.         TBA
  1964.  
  1965.      SYNTAX
  1966.         #include <TBA.h>
  1967.         int r = fcntl(fd, req, arg)
  1968.         int fd;
  1969.         int req;
  1970.         int arg;
  1971.  
  1972.     DESCRIPTION
  1973.         fcntl may be used to control various aspects of an fd and is a higher
  1974.         level call than ioctl.  Currently, nothing truly significant can be
  1975.         accomplished by a fcntl call for files.  However, fcntl fully supports
  1976.         programmer simulated file descriptors.
  1977.  
  1978.         :: NOTE:  Refer to the file_descriptor manual page for general
  1979.         :: information Unlike file pointers and file handles, the file
  1980.         :: descriptor is checked for validity and if illegal, an error will be
  1981.         :: returned.
  1982.  
  1983.     INPUTS
  1984.         int fd;        file descriptor to operate on
  1985.  
  1986.         int req;       request from <fcntl.h> (F_* defines)
  1987.  
  1988.         int arg;    control argument
  1989.  
  1990.     RESULTS
  1991.         int r;    result, error if less than 0
  1992.  
  1993.     SEE ALSO
  1994.         close, creat, fcntl, fdtofh, ioctl, isatty, lseek, mkdir, open, read,
  1995.         rmdir, unlink, write
  1996.  
  1997.     EXAMPLE
  1998.         TBA
  1999.  
  2000. dice/fcos                                                          dice/fcos
  2001.  
  2002.     FUNCTON
  2003.         return cosine of a float quantity
  2004.  
  2005.     LIBRARY
  2006.         TBA
  2007.  
  2008.     SYNTAX
  2009.         #include <math.h>
  2010.         float  c = fcos(d);
  2011.         float  d;
  2012.  
  2013.     DESCRIPTION
  2014.         fcos returns the cosine of a floating point quantity.
  2015.  
  2016.     INPUTS
  2017.         float d;     float floating point value
  2018.  
  2019.      RESULTS
  2020.         float c;     result float  floating point value
  2021.  
  2022.     SEE ALSO
  2023.         acos, asin, atan, cos, exp, fabs, log, log10, pow, sin, sqrt, tan
  2024.         facos, fasin, ...
  2025.  
  2026.     EXAMPLE
  2027.         /*
  2028.          *  compile with the math library -lm
  2029.          */
  2030.         #include <math.h>
  2031.         #include <stdio.h>
  2032.         
  2033.         main()
  2034.         {
  2035.            {
  2036.               double a = cos(0.25);
  2037.               printf("cos 0.25 = %lf\n", a);  /* 0.9689 */
  2038.            }
  2039.            {
  2040.               /*  less accuracy   */
  2041.               float a = fcos(0.25);
  2042.               printf("cos 0.25 = %lf\n", (double)a);
  2043.            }
  2044.            return(0);
  2045.         }
  2046.  
  2047. dice/fdopen                                                      dice/fdopen
  2048.  
  2049.     FUNCTION
  2050.         associate a file pointer with an open file descriptor
  2051.  
  2052.     LIBRARY
  2053.         TBA
  2054.  
  2055.     SYNTAX
  2056.         #include <stdio.h>
  2057.         FILE *fp = fdopen(fd, modes);
  2058.         int fd; char *modes;
  2059.  
  2060.     DESCRIPTION
  2061.         fdopen associates an open file descriptor with a file pointer.
  2062.  
  2063.         :: NOTE: Once fclose is used, the file pointer will also close the
  2064.         :: file descriptor.  Refer to the fopen manual page for a description
  2065.         :: of available modes. Also, when you use fdopen the file will not be
  2066.         :: truncated and if you specify mode a for append, the file descriptor
  2067.         :: must have been opened with the O_APPEND flag.  That is, the mode
  2068.         :: string should be similar to the open flags that were used to open
  2069.         :: the file descriptor. Refer to the file_pointer manual page for
  2070.         :: general information
  2071.  
  2072.     INPUTS
  2073.         int fd;    file descriptor to associated with a new file pointer
  2074.  
  2075.         char *modes;    modes string, such as "r+".
  2076.  
  2077.     RESULTS
  2078.         FILE *fp;     new file pointer or NULL if an error occured
  2079.  
  2080.     SEE ALSO
  2081.         fopen, fread, fwrite, fgets, fputs
  2082.  
  2083.     EXAMPLE
  2084.         TBA
  2085.  
  2086. dice/fdtofh                                                      dice/fdtofh
  2087.  
  2088.     FUNCTION
  2089.         return AmigaDOS file handle for file descriptor
  2090.  
  2091.     LIBRARY
  2092.         TBA
  2093.  
  2094.      SYNTAX
  2095.         #include <TBA.h>
  2096.         BPTR fh = fdtofh(fd);
  2097.         int fd;
  2098.  
  2099.          DESCRIPTION
  2100.         fdtofh returns the AmigaDOS file handle associated with a file
  2101.         descriptor or NULL if the file descriptor is illegal or simulated. 
  2102.         You may then make AmigaDOS library calls using the file handle.
  2103.  
  2104.     INPUTS
  2105.         int fd;    file descriptor
  2106.  
  2107.     RESULTS
  2108.         BPTR fh;    associated file handle or NULL
  2109.  
  2110.       SEE ALSO
  2111.         close, creat, fcntl, ioctl, isatty, lseek, mkdir, open, read, rmdir,
  2112.         unlink, write
  2113.  
  2114.     EXAMPLE
  2115.         #include <exec/types.h>
  2116.         
  2117.         main()
  2118.         {
  2119.            BPTR fh;
  2120.            write(1, "FuBar\n", 6);
  2121.            if (fh = fdtofh(1))
  2122.               Write(fh, "FuBar\n", 6);
  2123.            return(0);
  2124.         }
  2125.  
  2126. dice/feof                                                          dice/feof
  2127.  
  2128.     FUNCTION
  2129.         return EOF condition for File Pointer
  2130.  
  2131.     LIBRARY
  2132.         TBA
  2133.  
  2134.     SYNTAX
  2135.         #include <stdio.h>
  2136.         int r = feof(fp);
  2137.         (MACRO) FILE *fp;
  2138.  
  2139.     DESCRIPTION
  2140.         feof returns the EOF status of a file pointer.  The status is not
  2141.         changed by this macro.  0 is returned if no EOF condition exists,
  2142.         non-zero if an EOF condition exists (not necessarily 1 or -1, just
  2143.         non-zero).  Use clearerr to clear the EOF condition.  Also, fseek and
  2144.         rewind also clear an EOF condition.
  2145.  
  2146.         :: NOTE: Refer to the file_pointer manual page for general
  2147.         :: information.
  2148.  
  2149.     INPUTS
  2150.         FILE *fp;     file pointer
  2151.  
  2152.     RESULTS
  2153.         int r;      0 if no EOF condition exists, != 0 if an EOF condition exists
  2154.         (not necessarily 1 or -1).
  2155.  
  2156.          SEE ALSO
  2157.         fopen, fclose, fread, fwrite, fgets, fputs
  2158.  
  2159.     EXAMPLE
  2160.         TBA
  2161.  
  2162. dice/ferror                                                      dice/ferror
  2163.  
  2164.     FUNCTION
  2165.         return ERROR condition for file pointer
  2166.  
  2167.     LIBRARY
  2168.         TBA
  2169.  
  2170.     SYNTAX
  2171.         #include <stdio.h> int r = ferror(fp); (MACRO) FILE *fp;
  2172.  
  2173.       DESCRIPTION
  2174.         ferror returns the ERROR status of a file pointer.  The status is not
  2175.         changed by this macro.  0 is returned if no ERROR condition exists,
  2176.         non-zero if an ERROR condition exists (not necessarily 1 or -1, just
  2177.         non-zero).
  2178.  
  2179.         :: NOTE: Refer to the file_pointer manual page for general
  2180.         :: information.
  2181.  
  2182.     INPUTS
  2183.         FILE *fp;      file pointer
  2184.  
  2185.     RESULTS
  2186.         int r;     0 if no ERROR condition exists, != 0 if an ERROR condition
  2187.         exists (not necessarily 1 or -1).
  2188.  
  2189.     SEE ALSO
  2190.         fopen, fclose, fread, fwrite, fgets, fputs
  2191.  
  2192.     EXAMPLE
  2193.         TBA
  2194.  
  2195. dice/fexp                                                          dice/fexp
  2196.  
  2197.     FUNCTION
  2198.         return e to the power of the float quantity
  2199.  
  2200.     LIBRARY
  2201.         TBA
  2202.  
  2203.     SYNTAX
  2204.         #include <math.h>
  2205.         float  c = fexp(d); 
  2206.         float  d;
  2207.  
  2208.     DESCRIPTION
  2209.         fexp returns e to the power of the floating point quantity
  2210.  
  2211.     INPUTS
  2212.         float d;    float floating point value
  2213.  
  2214.     RESULTS
  2215.         float c;    result float  floating point value
  2216.  
  2217.     SEE ALSO
  2218.         acos, asin, atan, cos, exp, fabs, log, log10, pow, sin,  sqrt, tan
  2219.         facos, fasin, ...
  2220.  
  2221.     EXAMPLE
  2222.         /*
  2223.          *  compile with the math library -lm
  2224.          */
  2225.         #include <math.h>
  2226.         #include <stdio.h>
  2227.         
  2228.         main()
  2229.         {
  2230.            {
  2231.               double a = exp(0.25);
  2232.               printf("exp 0.25 = %lf\n", a); /* 1.284   */
  2233.            }
  2234.            {
  2235.               /*  less accuracy   */
  2236.               float a = fexp(0.25);
  2237.               printf("exp 0.25 = %lf\n", (double)a);
  2238.            }
  2239.            return(0);
  2240.         }
  2241.  
  2242. dice/ffabs                                                        dice/ffabs
  2243.  
  2244.     FUNCTION
  2245.         return the absolute value of a float quantity
  2246.  
  2247.     LIBRARY
  2248.         TBA
  2249.  
  2250.     SYNTAX
  2251.         #include <math.h>
  2252.         float  c = ffabs(d);
  2253.         float  d;
  2254.  
  2255.     DESCRIPTION
  2256.         ffabs returns the absolute value of a floating point quantity.
  2257.  
  2258.     INPUTS
  2259.         float d;     float floating point value
  2260.  
  2261.     RESULTS
  2262.         int arg;     control argument
  2263.  
  2264.         int r;     result, error if less than 0.
  2265.  
  2266.     SEE ALSO
  2267.         acos, asin, atan, cos, exp, fabs, log, log10, pow, sin,  sqrt, tan
  2268.         facos, fasin, ...
  2269.  
  2270.     EXAMPLE
  2271.         /*
  2272.          *  compile with the math library -lm
  2273.          */
  2274.         #include <math.h>
  2275.         #include <stdio.h>
  2276.         main()
  2277.         {
  2278.            {
  2279.                double a = fabs(-0.25);
  2280.                printf("fabs -0.25 = %lf\n", a); /*  0.25  */
  2281.            }
  2282.            {
  2283.                /*  less accuracy   */
  2284.               float a = ffabs(-0.25);
  2285.               printf("fabs -0.25 = %lf\n", (double)a);
  2286.            }
  2287.            return(0);
  2288.         }
  2289.  
  2290. dice/fflush                                                      dice/fflush
  2291.  
  2292.     FUNCTION
  2293.         flush buffers to file
  2294.  
  2295.     LIBRARY
  2296.         TBA
  2297.  
  2298.       SYNTAX
  2299.         #include <stdio.h>
  2300.         int error = fflush(fp);
  2301.         FILE *fp;
  2302.  
  2303.      DESCRIPTION
  2304.         fflush writes out any buffered data out to the file descriptor
  2305.         associated with the file pointer. Normally a file is either
  2306.         unbuffered, line buffered, or fully buffered;  fflush is useful in the
  2307.         latter two cases as is shown by the example. The function will return
  2308.         -1 if a write error occured, 0 if no error occured.
  2309.  
  2310.         :: NOTE: Refer to the file_pointer manual page for general
  2311.         :: information.
  2312.  
  2313.     INPUTS
  2314.         FILE *fp;     file pointer
  2315.  
  2316.     RESULTS
  2317.         int  error;    0 if no error, -1 on error.
  2318.  
  2319.     SEE ALSO
  2320.         fopen, fclose, fread, fwrite, fgets, fputs
  2321.  
  2322.      EXAMPLE
  2323.         /*
  2324.          *  Since text to stdout is normally line buffered, if we do
  2325.          *  not write out a newline '\n' then the line is still
  2326.          *  buffered in memory and we have to fflush() to write it
  2327.          *  out.
  2328.          */
  2329.         #include <stdio.h>
  2330.         main()
  2331.         {
  2332.            char buf[256];
  2333.            printf("Enter a number -");
  2334.            fflush(stdout);
  2335.            gets(buf);
  2336.            printf("Munch Munch...");
  2337.            fflush(stdout);
  2338.            sleep(1);
  2339.            puts("Thanks!");
  2340.         }
  2341.  
  2342. dice/fgetc,getc                                              dice/fgetc,getc
  2343.  
  2344.     FUNCTION
  2345.         fgetc: get a single character from a file pointer;
  2346.  
  2347.         getc: get a single character from a file pointer (MACRO)
  2348.  
  2349.     LIBRARY
  2350.         TBA
  2351.  
  2352.      SYNTAX
  2353.         #include <stdio.h>
  2354.         int c = fgetc(fp);
  2355.         int c = getc(fp);
  2356.         (MACRO) FILE *fp;
  2357.  
  2358.      DESCRIPTION
  2359.         getc and fgetc both read a single character from a file pointer.  The
  2360.         value returned is actually an int because EOF (-1) must be
  2361.         differentiated from a 255.  Each returns an integer 0-255 or EOF (-1)
  2362.         if an end of file occurs.
  2363.  
  2364.         :: NOTE: Refer to the file_pointer manual page for general 
  2365.         :: information.
  2366.  
  2367.     INPUTS
  2368.         FILE *fp;
  2369.         file pointer
  2370.  
  2371.     RESULTS
  2372.         int c;     character 0 to 255, or EOF (-1).
  2373.  
  2374.      SEE ALSO
  2375.         putc, fputc, fread, fwrite
  2376.  
  2377.      EXAMPLE
  2378.         /*
  2379.          *  copy stdin to stdout using getc/putc.  Normally one uses
  2380.          *  fread/fwrite, but I'll save that for the fread manual
  2381.          *  page.
  2382.          *  note that I output the initial message to stderr so it
  2383.          *  does not get stuck into stdout in case the user has
  2384.          *  redirected stdout.
  2385.          */
  2386.         #include <stdio.h>
  2387.         main()
  2388.         {
  2389.            int c;
  2390.            fputs("Type a couple of lines, then ^\ (EOF)\n", stderr);
  2391.            while ((c = getc(stdin)) != EOF)
  2392.            {
  2393.                putc(c, stdout);
  2394.            }
  2395.            return(0);
  2396.         }
  2397.  
  2398. dice/fgetpos                                                    dice/fgetpos
  2399.  
  2400.     FUNCTION
  2401.         get current file position
  2402.  
  2403.     LIBRARY
  2404.         TBA
  2405.  
  2406.           SYNTAX
  2407.         #include <stdio.h>
  2408.         int error = fgetpos(fp, &pos);
  2409.         fpos_t pos;
  2410.  
  2411.          DESCRIPTION
  2412.         fgetpos returns the current seek position and is roughly equivalent to
  2413.         ftell.  fgetpos is a new ANSI call to better support C compilers that
  2414.         use 16 bit integers.  DICE uses 32 bit integers so fgetpos is not so
  2415.         useful.  fgetpos takes a file pointer and the address of a fpos_t type
  2416.         (a long).  It fills the fpos_t variable with the current file position
  2417.         and returns 0 if all went well, non-zero if an error occured.
  2418.  
  2419.         :: NOTE:  Refer to the file_pointer manual page for general
  2420.         :: information.
  2421.  
  2422.     INPUTS
  2423.         FILE *fp;     file pointer
  2424.  
  2425.         fpos_t *pos;     pointer to an fpos_t type that the position is loaded
  2426.         into.
  2427.  
  2428.     RESULTS
  2429.         int error;     0 if no error, non-zero on error
  2430.  
  2431.     SEE ALSO
  2432.         ftell, rewind, fseek, rewind
  2433.  
  2434.      EXAMPLE
  2435.         /*
  2436.          *  return the length of the file specified on the command
  2437.          *  line. P.S. it is more efficient to use open/lseek/close
  2438.          *  instead of fopen/fseek/fgetpos/fclose
  2439.          */
  2440.         #include <stdio.h>
  2441.         
  2442.         main(ac, av)
  2443.         int ac;
  2444.         char **av;
  2445.         {
  2446.            FILE *fp;
  2447.            fpos_t off;
  2448.            if (ac == 1)
  2449.            {
  2450.               puts("Expected a filename argument");
  2451.               exit(1);
  2452.            }
  2453.            fp = fopen(av[1], "r");
  2454.            if (fp == NULL)
  2455.            {
  2456.               printf("Unable to open %s\n", av[1]);
  2457.               exit(10);
  2458.            }
  2459.            fseek(fp, 0L, SEEK_END);
  2460.            if (fgetpos(fp, &off))
  2461.            {
  2462.               puts("Error getting file position");
  2463.               exit(20);
  2464.            }
  2465.            fclose(fp);
  2466.            printf("File %s is %d bytes\n", av[1], off);
  2467.            return(0);
  2468.         }
  2469.  
  2470. dice/fgets                                                        dice/fgets
  2471.  
  2472.     FUNCTION
  2473.         get a line from a file pointer
  2474.  
  2475.     LIBRARY
  2476.         TBA
  2477.  
  2478.       SYNTAX
  2479.         #include <stdio.h>
  2480.         char *ptr = fgets(buf, maxlen, fp);
  2481.         char *buf;
  2482.         int maxlen;
  2483.         FILE *fp;
  2484.  
  2485.      DESCRIPTION
  2486.         fgets gets a line from the specified file pointer, returning the first
  2487.         argument (buf) or NULL if an error or EOF occurs. fgets stores the
  2488.         line in buf, up to maxlen characters. This maximum includes a
  2489.         terminating newline '\n' andNULL '\0'. It is common to get confused
  2490.         between gets, fgets, puts, and fputs.  gets strips off any newline
  2491.         '\n' and puts adds one while fgets keeps the newline at the end of the
  2492.         line and fputs does NOT add one.  gets and puts work on stdin and
  2493.         stdout while fgets and fputs work on arbitrary file pointers. If more
  2494.         than maxlen - 1 characters are in the line fgets will terminate
  2495.         operation and put a NULL as the last character (so the buffer will
  2496.         still be a valid string).
  2497.  
  2498.         :: NOTE: Refer to the file_pointer manual page for general
  2499.         :: information.
  2500.  
  2501.     INPUTS
  2502.         char *buf;    buffer
  2503.  
  2504.         int  maxlen;    maximum buffer size
  2505.  
  2506.         FILE *fp;    file pointer
  2507.  
  2508.      RESULTS
  2509.         char *ptr;    buf if all is well, or NULL if error or EOF
  2510.  
  2511.          SEE ALSO
  2512.         gets, puts, fputs, fread, getc, fgetc
  2513.  
  2514.      EXAMPLE
  2515.         #include <stdio.h>
  2516.         main()
  2517.         {
  2518.            unsigned char buf[128];
  2519.            short i;
  2520.            printf("Enter a line - ");
  2521.            fflush(stdout);
  2522.            if (fgets(buf, sizeof(buf), stdin) == NULL)
  2523.               exit(1);
  2524.            printf("In Hex: ");
  2525.            for (i = 0; buf[i]; ++i) printf(" %02x", buf[i]);
  2526.            puts("");
  2527.            return(0);
  2528.         }
  2529.  
  2530. dice/fhprintf                                                  dice/fhprintf
  2531.  
  2532.     FUNCTION
  2533.         formatted printing to a DOS file handle
  2534.  
  2535.     LIBRARY
  2536.         TBA
  2537.  
  2538.       SYNTAX
  2539.         #include <TBA.h>
  2540.         int n = fhprintf(fh, ctl, ...);
  2541.         BPTR fh;
  2542.         const char *ctl;
  2543.  
  2544.      DESCRIPTION
  2545.         fhprintf provides a method of using DICE's pfmt lib to do formatted
  2546.         printing to a file handle instead of a stdio file pointer. Output is
  2547.         unbuffered and thus not very efficient, but the call can be extremely
  2548.         useful when debugging libraries and such.
  2549.  
  2550.     INPUTS
  2551.         BPTR fh;     DOS file handle
  2552.  
  2553.         const char *ctl;    format string, see printf()
  2554.  
  2555.     RESULTS
  2556.         int n;    number of characters output
  2557.  
  2558.     SEE ALSO
  2559.         printf, sprintf, vsprintf, fprintf, vfprintf
  2560.  
  2561.      EXAMPLE
  2562.         void _main(ac, av)
  2563.         int ac;
  2564.         char *av[];
  2565.         {
  2566.            fhprintf(Output(), "hello world %d!\n", 23);
  2567.         }
  2568.  
  2569. dice/file_descriptor                                    dice/file_descriptor
  2570.  
  2571.     FUNCTION
  2572.         file descriptor
  2573.  
  2574.     DESCRIPTION
  2575.         A file descriptor is the lowest portable access to the file system a C
  2576.         program may make.  File descriptors are used with open, read, write,
  2577.         close, etc.  A file descriptor is unbuffered (that is, every operation
  2578.         goes to the kernel and does not get buffered locally).
  2579.  
  2580.         :: NOTE: Remember that a file descriptor is different from a STDIO
  2581.         :: file pointer (see the file_pointer manual page) and an AmigaDOS
  2582.         :: file handle.
  2583.  
  2584. dice/fileno                                                      dice/fileno
  2585.  
  2586.     FUNCTION
  2587.         return file descriptor given a file pointer
  2588.  
  2589.     LIBRARY
  2590.         TBA
  2591.  
  2592.       SYNTAX
  2593.         #include <stdio.h>
  2594.         int fd = fileno(fp);
  2595.         (MACRO) FILE *fp;
  2596.  
  2597.      DESCRIPTION
  2598.         The fileno macro returns the file descriptor (open, close, read,
  2599.         write) associated with the file pointer (fopen, fclose, fread,
  2600.         fwrite). This is still not the AmigaDOS file handle; to get that you
  2601.         must use the fdtofh call.
  2602.  
  2603.         || WARNING! If you use the file descriptor of a file pointer the file
  2604.         || pointer will get its seek position confused. Additionally, there
  2605.         || might be unflushed data in the file pointer's buffers that has not
  2606.         || been written out to the file descriptor yet.  There also might be
  2607.         || unread input on the file pointer's input buffers already read from
  2608.         || the file descriptor.
  2609.  
  2610.         :: NOTE:  Refer to the file_pointer manual page for general
  2611.         :: information.
  2612.  
  2613.     INPUTS
  2614.         FILE *fp;    file pointer
  2615.  
  2616.      RESULTS
  2617.         int  fd;    associated file descriptor
  2618.  
  2619.          SEE ALSO
  2620.         fdopen, fopen, fclose, open, close
  2621.  
  2622.     EXAMPLE
  2623.         TBA
  2624.  
  2625. dice/file_pointer                                          dice/file_pointer
  2626.  
  2627.     FUNCTION
  2628.         STDIO file_pointer
  2629.  
  2630.     DESCRIPTION
  2631.         A file pointer is the basis for STDIO, a standard file buffering   
  2632.         package across all versions of C.  The specific Amiga implementation
  2633.         uses file descriptors (see the file_descriptor manual page) as its
  2634.         interface to the filesystem.    Remember that a stdio file pointer is
  2635.         not a file descriptor nor an AmigaDOS file handle.  You may call only
  2636.         stdio routines (fopen, fclose, fread, fwrite) with file pointers. Some
  2637.         C implementations flush stdout whenever stdin is read.  DICE does not
  2638.         do this.
  2639.  
  2640. dice/fopen                                                        dice/fopen
  2641.  
  2642.     FUNCTION
  2643.         open a file and create a file pointer
  2644.  
  2645.     LIBRARY
  2646.         TBA
  2647.  
  2648.      SYNTAX
  2649.         #include <stdio.h>
  2650.         FILE *fp = fopen(filename, modes)
  2651.         char *filename;
  2652.         char *modes;
  2653.  
  2654.     DESCRIPTION
  2655.         fopen is the grand master of stdio:  it opens and possibly creates a
  2656.         file and returns a new file pointer for use by the program. The first
  2657.         argument is the file to open, the second is a string containing one or
  2658.         mode characters defined as follows:
  2659.  
  2660.         Mode, Usage
  2661.  
  2662.         r, open for reading,, the file must already exist
  2663.  
  2664.         w, open for writing,, the file is created if it does not exist,,
  2665.         truncated if it does
  2666.  
  2667.         a, open for append,, writes always append to the file.
  2668.  
  2669.         a, the file starts out positioned at the end instead of at the
  2670.         beginning.  This mode also creates the file but only if it does not
  2671.         already exist.
  2672.  
  2673.         r+, also allows writing to the file in addition to reading
  2674.  
  2675.         w+, also allows reading from the file
  2676.  
  2677.         b, open for binary read/write,, else the file is assumed to contain
  2678.         text (this is ignored by DICE since there is no difference on the
  2679.         Amiga).
  2680.  
  2681.         All combinations except "rw" are allowed.  One uses "r+" or "w+"
  2682.         instead of "rw".  By the above description "r+" is used to update an
  2683.         existing file while "w+" is used to create a new file and then allow
  2684.         reads as well as writes to it. "wa" is equivalent to creating a new
  2685.         file and then appending to it. "r+a" is equivalent to appending to an
  2686.         already existing file. Other examples of valid modes combinations:
  2687.         "r+b", "w+b", "rb", "wb", "ab", "w", "r", "r+", "a", etc...
  2688.  
  2689.         :: NOTE: Refer to the file_pointer manual page for general
  2690.         :: information.
  2691.  
  2692.     INPUTS
  2693.         char *filename;     file name to open
  2694.  
  2695.         char *modes;    open modes string
  2696.  
  2697.     RESULTS
  2698.              FILE *fp;    new file pointer
  2699.  
  2700.     SEE ALSO
  2701.         fdopen, fclose, open, close
  2702.  
  2703.     EXAMPLE
  2704.         TBA
  2705.  
  2706. dice/fputc,putc                                              dice/fputc,putc
  2707.  
  2708.     FUNCTION
  2709.         fputc: write a single character to a file pointer;
  2710.         putc: write a single character to a file pointer (MACRO)
  2711.  
  2712.     LIBRARY
  2713.         TBA
  2714.  
  2715.           SYNTAX
  2716.         #include <stdio.h>
  2717.         int c = fputc(c, fp);
  2718.         int c = putc(c, fp);
  2719.         FILE *fp;
  2720.  
  2721.          DESCRIPTION
  2722.         fputc writes a single character to a file pointer.  If all goes well
  2723.         the character is returned, else EOF is returned. fputc is a function
  2724.         call while putc is a macro
  2725.  
  2726.         :: NOTE: Refer to the file_pointer manual page for general
  2727.         :: information.
  2728.  
  2729.     INPUTS
  2730.         int c;    character to write
  2731.  
  2732.         FILE *fp;    file pointer
  2733.  
  2734.     RESULTS
  2735.         int c;     character written (same as first argument) or EOF if error.
  2736.  
  2737.     SEE ALSO
  2738.         getc, putc, fputc, fread, fwrite, puts, fputs, gets, fgets
  2739.  
  2740.      EXAMPLE
  2741.         /*
  2742.          *  copy stdin to stdout using fgetc/fputc. Normally one
  2743.          *  uses fread/fwrite, but I'll save that for the fread
  2744.          *  manual page. note that I output the initial message to
  2745.          *  stderr so it does not get stuck into stdout in case
  2746.          *  the user has redirected stdout.
  2747.          */
  2748.         #include <stdio.h>
  2749.         main()
  2750.         {
  2751.            int c;
  2752.            fputs("Type a couple of lines, then ^\ (EOF)\n",
  2753.               stderr);
  2754.            while ((c = fgetc(stdin)) != EOF)
  2755.            {
  2756.               fputc(c, stdout);
  2757.            }
  2758.            return(0);
  2759.         }
  2760.  
  2761. dice/fputs,puts                                              dice/fputs,puts
  2762.  
  2763.     FUNCTION
  2764.         fputs: write a string to a file pointer;
  2765.         puts: write a string to stdout and also write a newline
  2766.  
  2767.      SYNTAX
  2768.         #include <stdio.h>
  2769.         int error = fputs(s, fp);
  2770.         int error = puts(s);
  2771.         const char *s;
  2772.         FILE *fp;
  2773.  
  2774.     LIBRARY
  2775.         TBA
  2776.  
  2777.     DESCRIPTION
  2778.         fputs writes a string to a file pointer all the way up to, but not
  2779.         including, the NULL.  puts does the same thing but to stdout, and puts
  2780.         additionally writes a `newline out.
  2781.  
  2782.         :: NOTE: Refer to the file_pointer manual page for general
  2783.         :: information.
  2784.  
  2785.         It is common to get confused between fputs and puts. Remember that
  2786.         puts adds a newline to the output while fputs does not.  gets strips
  2787.         the newline from an input line while fgets does not.
  2788.  
  2789.     INPUTS
  2790.         char *s;     string to write
  2791.  
  2792.         FILE *fp;     file pointer
  2793.  
  2794.     RESULTS
  2795.         int  error;     0 or positive if all went ok, else negative. Note that
  2796.         unlike *printf() routines the numberr of chars written out is NOT
  2797.         returned.
  2798.  
  2799.     SEE ALSO
  2800.         getc, putc, fputc, fread, fwrite, gets, fgets
  2801.  
  2802.          EXAMPLE
  2803.         #include <stdio.h>
  2804.         main()
  2805.         {
  2806.            fputs("This is a test of fputs\n", stdout);
  2807.                                               /* note newline */
  2808.             puts("This is a test of puts");   /*  note lack of */
  2809.             puts("That's it!");
  2810.             return(0);
  2811.         }
  2812.  
  2813. dice/fseek                                                        dice/fseek
  2814.  
  2815.     FUNCTION
  2816.         seek within a file pointer
  2817.  
  2818.     LIBRARY
  2819.         TBA
  2820.  
  2821.     SYNTAX
  2822.         #include <stdio.h>
  2823.         int error = fseek(fp, offset, how);
  2824.         FILE *fp;
  2825.         long offset;
  2826.         int how;
  2827.  
  2828.     DESCRIPTION
  2829.         fseek changes the current seek position within a file. Offset is
  2830.         interpreted according to the how argument:
  2831.  
  2832.         , , 
  2833.  
  2834.         SEEK_SET, 0, skip to position relative to beginning of file
  2835.  
  2836.         SEEK_CUR, 1, skip to position relative to current position in file
  2837.  
  2838.         SEEK_END, 2, skip to position relative to end of file.
  2839.  
  2840.         So, for example, one may seek to the beginning of a file by fseek(fp,
  2841.         0L, SEEK_SET);, to the end of the file by fseek(fp, 0L, SEEK_END);. 
  2842.         Calling getc at this time would return an immediate EOF.  You can skip
  2843.         characters in a file with something like fseek(fp, 5L, SEEK_CUR);
  2844.         which skips 5 characters.  Note that when seeking relative to the end
  2845.         of the file, negative offsets are used.  For example, to seek to the
  2846.         very last character in the file you would use fseek(fp, -1L,
  2847.         SEEK_END); fseek returns 0 on success, a negative number on ERROR.  A
  2848.         common mistake is to expect fseek to return the new position  of the
  2849.         file but this is not what is returned.  Use ftell or fgetpos to
  2850.         determine the current offset into a file.
  2851.  
  2852.         :: NOTE: Refer to the file_pointer manual page for general information
  2853.         :: fseek flushes any buffered write data before seeking.
  2854.  
  2855.     INPUTS
  2856.         FILE *fp;     file pointer to seek
  2857.  
  2858.         long offset;     offset relative to how
  2859.  
  2860.         int how;     0, 1, or 2 (absolute, relative, end- relative)
  2861.  
  2862.     RESULTS
  2863.             int error;
  2864.  
  2865.     SEE ALSO
  2866.         ftell, fgetpos, fsetpos, rewind
  2867.  
  2868.     EXAMPLE
  2869.         TBA
  2870.  
  2871. dice/fread                                                        dice/fread
  2872.  
  2873.     FUNCTION
  2874.         read data from a file pointer
  2875.  
  2876.     LIBRARY
  2877.         TBA
  2878.  
  2879.     SYNTAX
  2880.         #include <stdio.h>
  2881.         size_t robjs = fread(buf, objsize, nobjs, fp);
  2882.         void *buf; size_t objsize; size_t nobjs;
  2883.         FILE *fp;
  2884.  
  2885.     DESCRIPTION
  2886.         fread reads an arbitrary number of objects from a file pointer into
  2887.         the specified buffer and returns the actual number of objects read. 
  2888.         If the return value robjs is not equal to nobjs then fread was unable
  2889.         to read the requested number of objects due to either a read error or
  2890.         an EOF condition.  If the file is already completely exhausted fread
  2891.         simply returns 0. Having two size arguments, an object size and a
  2892.         number of objects, simplifies the reading of structure arrays off
  2893.         disk.
  2894.  
  2895.         :: NOTE: To use fread to read an arbitrary number of bytes one
  2896.         :: normally uses the form: r = fread(buf, 1, n, fp); that is, n
  2897.         :: objects of size 1.  fread will attempt to read objsize * nobjs
  2898.         :: bytes into the specified buffer.
  2899.  
  2900.     INPUTS
  2901.         void   *buf;    buffer to load data into
  2902.  
  2903.         size_t objsize;    size of one object
  2904.  
  2905.         size_t nobjs;    number of objects to read
  2906.  
  2907.         FILE   *fp;    file pointer to read objects from
  2908.  
  2909.     RESULTS
  2910.               size_t robjs;    number of objects actually read or 0 if EOF or ERROR.
  2911.  
  2912.     SEE ALSO
  2913.         fwrite, fopen, fclose, fseek, ftell, rewind
  2914.  
  2915.     EXAMPLE
  2916.         TBA
  2917.  
  2918. dice/free                                                          dice/free
  2919.  
  2920.     FUNCTION
  2921.         free memory allocated by calloc, malloc, or strdup
  2922.  
  2923.     LIBRARY
  2924.         TBA
  2925.  
  2926.     SYNTAX
  2927.         #include <TBA.h>
  2928.         void free(ptr); 
  2929.         void *ptr;
  2930.  
  2931.     DESCRIPTION
  2932.         free frees memory allocated by calloc, malloc, or strdup.
  2933.  
  2934.         :: NOTE: It is illegal to free(NULL). If free is given an illegal
  2935.         :: pointer or NULL, it will freeze the process by calling wait(0L).
  2936.  
  2937.     INPUTS
  2938.         void *ptr;    pointer to memory to free
  2939.  
  2940.     RESULTS
  2941.         none
  2942.  
  2943.     SEE ALSO
  2944.         malloc, calloc, strdup
  2945.  
  2946.     EXAMPLE
  2947.         see calloc example
  2948.  
  2949. dice/freopen                                                    dice/freopen
  2950.  
  2951.     FUNCTION
  2952.         reopen a new file using an existing file pointer, the existing file is
  2953.         closed before it is reused.
  2954.  
  2955.     LIBRARY
  2956.         TBA
  2957.  
  2958.     SYNTAX
  2959.         #include <stdio.h>
  2960.         FILE *fp = freopen(filename, modes, ofp)
  2961.         char *filename; 
  2962.         char *modes;
  2963.         FILE *ofp;
  2964.  
  2965.     DESCRIPTION
  2966.         freopen works exactly like fopen but takes an additional argument,  a
  2967.         file pointer to reuse. This file pointer, ofp, must be `reference a
  2968.         valid open file.  freopen will close out ofp then reuse the descriptor
  2969.         to open the new file, returning ofp (fp == ofp) on success, NULL on
  2970.         failure. If the freopen fails NULL is returned and the original file
  2971.         pointer is still closed, but not freed so you may call freopen again
  2972.         with the same ofp, even though it has already been closed.  Refer to
  2973.         the fopen manual page for information on the modes string. freopen is
  2974.         often used to change a program's stdin, stdout, or stderr though to be
  2975.         frank, using a separate file pointer is normally much more modular.
  2976.  
  2977.         || WARNING!  ANSI does not specify that the ofp can be used in a
  2978.         || second freopen if the first freopen using ofp fails (returns NULL).
  2979.         || Many implementations free the file pointer. This just might be the
  2980.         || proper way of doing things but I don't know.  I suggest you do not
  2981.         || use DICE's feature in that respect as I might have to change it
  2982.         || back to free ofp if the new file is unopenable.
  2983.  
  2984.         :: NOTE Refer to the file_pointer manual page for general information
  2985.  
  2986.     INPUTS
  2987.         char *filename;    file name to open
  2988.  
  2989.         char*modes;    open modes string
  2990.  
  2991.         FILE *ofp;    open file pointer to reuse
  2992.  
  2993.     RESULTS
  2994.         FILE *fp;     same as ofp if the new open worked, NULL otherwise
  2995.  
  2996.     SEE ALSO
  2997.         fdopen, fopen, fclose, open, close
  2998.  
  2999.     EXAMPLE
  3000.         /*
  3001.          *  re-open stdin to an Amiga console device
  3002.          */
  3003.         #include <stdio.h>
  3004.         #include <assert.h>
  3005.         main()
  3006.         {
  3007.            char buf[256];
  3008.            assert(freopen("CON:0/0/320/100/freopen-in", "r",
  3009.                   stdin));
  3010.            assert(freopen("CON:320/0/320/100/freopen-out", "w",
  3011.                   stdout));
  3012.            /*
  3013.             *  set to line buffered
  3014.             */
  3015.            setvbuf(stdin, NULL, _IOLBF, 0);
  3016.            setvbuf(stdout, NULL, _IOLBF, 0);
  3017.            puts("Type a line in the second window");
  3018.            gets(buf);
  3019.            fclose(stdin);
  3020.            fclose(stdout);
  3021.            fprintf(stderr, "Your line was: %s\n", buf);
  3022.            return(0);
  3023.         }
  3024.  
  3025. dice/fsetpos                                                    dice/fsetpos
  3026.  
  3027.     FUNCTION
  3028.         set position within file pointer (nearly equivalent to fseek absolute)
  3029.  
  3030.     LIBRARY
  3031.         TBA
  3032.  
  3033.     SYNTAX
  3034.         #include <stdio.h>
  3035.         int error = fsetpos(fp, &pos);
  3036.         FILE *fp; fpos_t pos;
  3037.  
  3038.     DESCRIPTION
  3039.         fsetpos is a nearly useless call that is essentially the same as
  3040.         fseek(fp, (long)pos, 0); fsetpos seeks within a file pointer to the
  3041.         absolute position specified by an `fpos_t type.  The address of an
  3042.         `fpos_t object is passed to fsetpos. Normally one saves the current
  3043.         seek position into an fpos_t type using the fgetpos function, then
  3044.         seeks back using the fsetpos function.  In this way the programmer
  3045.         need not make any direct reference to the contents of the fpos_t type.
  3046.  
  3047.     INPUTS
  3048.         FILE *fp;    file pointer to seek
  3049.  
  3050.         fpos_t *pos;    pointer to fpos_t type previously
  3051.  
  3052.         initialized by a fgetpos() call.
  3053.  
  3054.     RESULTS
  3055.         int error;    0 if no error, < 0 if error
  3056.  
  3057.     SEE ALSO
  3058.         ftell, fsetpos, fseek, rewind
  3059.  
  3060.     EXAMPLE
  3061.         /*
  3062.          *  get a line, save current position, get rest of file, go
  3063.          * back to saved position, retrieve line again and print
  3064.          * again.
  3065.          */ 
  3066.         #include <stdio.h>
  3067.         main(ac, av)
  3068.         int ac;
  3069.         char **av;
  3070.         {
  3071.            FILE *fp;
  3072.            fpos_t save_pos;
  3073.            int count;
  3074.            char buf[256];
  3075.            if (ac == 1)
  3076.            {
  3077.               puts("Expected textfile argument");
  3078.               exit(1);
  3079.            }
  3080.            fp = fopen(av[1], "r");
  3081.            if (fp == NULL)
  3082.            {
  3083.               printf("Unable to open %s\n", av[1]);
  3084.               exit(1);
  3085.            }
  3086.            for  (count = 0; fgets(buf, sizeof(buf), fp); ++count)
  3087.            {
  3088.               if (count == 0) /*  just before second line */
  3089.                  fgetpos(fp, &save_pos);
  3090.               fprintf(stdout, "%-3d: %s", count + 1, buf);
  3091.            }
  3092.            if (count < 2)
  3093.            {
  3094.               puts("not enough lines in file for example!");
  3095.               exit(1);
  3096.            }
  3097.            puts("--end of file, now seeking back to line 2--");
  3098.            fsetpos(fp, &save_pos);
  3099.            if (fgets(buf, sizeof(buf), fp) == NULL)
  3100.            {
  3101.               puts("error!");
  3102.               exit(1);
  3103.            }
  3104.            fprintf(stdout, "%-3d: %s", 2, buf);
  3105.            fclose(fp);
  3106.            return(0);
  3107.         }
  3108.  
  3109. dice/fstat                                                        dice/fstat
  3110.  
  3111.     FUNCTION
  3112.         stat a file descriptor
  3113.  
  3114.     LIBRARY
  3115.         TBA
  3116.  
  3117.     SYNTAX
  3118.         #include <sys/stat.h>
  3119.         int error = fstat(fd, &stat_buf);
  3120.         struct stat stat_buf;
  3121.  
  3122.     DESCRIPTION
  3123.         fstat is a UNIX-compatible call that returns information pertaining to
  3124.         the file represented by an open file descriptor.  See stat for
  3125.         information on the struct stat fields.
  3126.  
  3127.         :: NOTE:  fstat works just like stat except you provide a UNIX file
  3128.         ::  descriptor (not an amigaDOS File Handle). 
  3129.         :: Under 2.0, ExamineFH will be used.  Under 1.3, the original path
  3130.         :: used to open the file will be stat'd, which ends up scanning the
  3131.         :: directory if the file was open for exclusive access.
  3132.  
  3133.     INPUTS
  3134.         int  fd;    file descriptor to stat
  3135.  
  3136.         struct stat *sbuf;      address of stat structure that will be filled in
  3137.  
  3138.     RESULTS
  3139.         int error;     0 on success, < 0 on error
  3140.  
  3141.     SEE ALSO
  3142.         chdir
  3143.  
  3144.     EXAMPLE
  3145.         #include <stdio.h>
  3146.         #include <fcntl.h>
  3147.         #include <sys/stat.h>
  3148.         
  3149.         main(ac, av)
  3150.         int ac;
  3151.         char *av[];
  3152.         {
  3153.            int fd;
  3154.            int r;
  3155.            struct stat stat_buf;
  3156.         
  3157.            if (ac == 1)
  3158.            {
  3159.               puts("test scratch_file");
  3160.               exit(1);
  3161.            }
  3162.            fd = open(av[1], O_WRONLY | O_CREAT);
  3163.            if (fd >= 0)
  3164.            {
  3165.               r = fstat(fd, &stat_buf);
  3166.               if (r < 0)
  3167.                  printf("Can't stat fd=%d\n", fd);
  3168.               else
  3169.                  printf("File is %d bytes long\n",
  3170.                  stat_buf.st_size);
  3171.               close(fd);
  3172.            }
  3173.            return(0);
  3174.         }
  3175.  
  3176. dice/ftell                                                        dice/ftell
  3177.  
  3178.     FUNCTION
  3179.         return current position within file pointer
  3180.  
  3181.     LIBRARY
  3182.         TBA
  3183.  
  3184.     SYNTAX
  3185.         #include <stdio.h>
  3186.         long pos = ftell(fp);
  3187.         FILE *fp;
  3188.  
  3189.     DESCRIPTION
  3190.         ftell returns the current absolute seek offset within a file pointer.
  3191.  
  3192.     INPUTS
  3193.         FILE *fp;    file pointer retrieve seek position from
  3194.  
  3195.     RESULTS
  3196.         long pos;    current absolute seek position in file
  3197.  
  3198.     SEE ALSO
  3199.         ftell, fgetpos, fsetpos, fseek, rewind
  3200.  
  3201.     EXAMPLE
  3202.         /*
  3203.          * get a line, save current position, get rest of file,
  3204.          * go backto saved position, retrieve line again and print
  3205.          * again.
  3206.          * like fsetpos() example but uses ftell()/fseek() instead
  3207.          */
  3208.         #include <stdio.h>
  3209.         main(ac, av)
  3210.         int ac;
  3211.         char **av;
  3212.         {
  3213.            FILE *fp;
  3214.            long save_pos;
  3215.            int count;
  3216.            char buf[256];
  3217.            if (ac == 1)
  3218.            {
  3219.               puts("Expected textfile argument");
  3220.               exit(1);
  3221.            }
  3222.            fp = fopen(av[1], "r");
  3223.            if (fp == NULL)
  3224.            {
  3225.               printf("Unable to open %s\n", av[1]);
  3226.               exit(1);
  3227.            }
  3228.            for (count = 0; fgets(buf, sizeof(buf), fp); ++count)
  3229.            {
  3230.               if (count == 0)     /*  just before second line */
  3231.                  save_pos = ftell(fp);
  3232.               fprintf(stdout, "%-3d: %s", count + 1, buf);
  3233.            }
  3234.            if (count < 2)
  3235.            {
  3236.               puts("not enough lines in file for example!");
  3237.               exit(1);
  3238.            }
  3239.            puts("--end of file, now seeking back to line 2--");
  3240.            fseek(fp, save_pos, SEEK_SET);
  3241.            if (fgets(buf, sizeof(buf), fp) == NULL)
  3242.            {
  3243.               puts("error!");
  3244.               exit(1);
  3245.            }
  3246.            fprintf(stdout, "%-3d: %s", 2, buf);
  3247.            fclose(fp);
  3248.            return(0);
  3249.         }
  3250.  
  3251. dice/fwrite                                                      dice/fwrite
  3252.  
  3253.     FUNCTION
  3254.         write data to a file pointer
  3255.  
  3256.     LIBRARY
  3257.         TBA
  3258.  
  3259.     SYNTAX
  3260.         #include <stdio.h>
  3261.         size_t robjs = fwrite(buf, objsize, nobjs, fp);
  3262.         const void *buf;
  3263.         size_t objsize;
  3264.         size_t nobjs;
  3265.         FILE *fp;
  3266.  
  3267.     DESCRIPTION
  3268.         fwrite writes the specified number of objects to a file pointer from
  3269.         the specified buffer and returns the actual number of objects written
  3270.         or 0 or -1 depending on the error.  If the return value robjs is not
  3271.         equal to nobjs then a write error occured. Having two size arguments,
  3272.         an object size and number of objects, simplifies the reading of
  3273.         structure arrays off disk.
  3274.  
  3275.         :: NOTE: To use fwrite to read an arbitrary number of bytes one
  3276.         :: normally uses the `form: r = fwrite(buf, 1, n, fp); that is, n
  3277.         :: objects of size 1.
  3278.  
  3279.     INPUTS
  3280.         void *buf;    buffer to copy data from
  3281.  
  3282.         size_t objsize;     size of one object
  3283.  
  3284.         size_t nobjs;     number of objects to write
  3285.  
  3286.         FILE *fp;     file pointer to read objects from
  3287.  
  3288.     RESULTS
  3289.         size_t robjs;    number of objects actually written (0 or EOF on error)
  3290.  
  3291.     SEE ALSO
  3292.         fread, fopen, fclose, fseek, ftell, rewind
  3293.  
  3294.     EXAMPLE
  3295.         /*
  3296.          *  NOTE:   run fread() example after this one to read data
  3297.          *  back from the file
  3298.          */
  3299.         #include <stdio.h>
  3300.         #define NOBJS   15
  3301.         typedef struct
  3302.         {
  3303.            short   a, b, c, d;
  3304.         }
  3305.         MyObj;
  3306.         main()
  3307.         {
  3308.            FILE *fp;
  3309.            MyObj O;
  3310.            if (fp = fopen("T:fwrite_tmp", "wb"))
  3311.            {
  3312.               short n;
  3313.               for (n = 0; n < NOBJS; ++n)
  3314.               {
  3315.                  O.a = n;
  3316.                  O.b = n * 2;
  3317.                  O.c = n * 3;
  3318.                  O.d = n * 4;
  3319.                  if (fwrite(&O, sizeof(MyObj), 1, fp) != 1)
  3320.                  {
  3321.                     puts("write error");
  3322.                     exit(1);
  3323.                  }
  3324.               }
  3325.            fclose(fp);
  3326.            }
  3327.            else
  3328.            {
  3329.               puts("Unable to create T:fwrite_tmp");
  3330.               exit(1);
  3331.            }
  3332.            return(0);
  3333.         }
  3334.  
  3335. dice/getchar                                                    dice/getchar
  3336.  
  3337.     FUNCTION
  3338.         get character from stdin (MACRO)
  3339.  
  3340.     LIBRARY
  3341.         TBA
  3342.  
  3343.     SYNTAX
  3344.         #include <stdio.h>
  3345.         int c = getchar();
  3346.  
  3347.     DESCRIPTION
  3348.         getchar returns the next available character on stdin or EOF if no
  3349.         more characters are available. getchar is equivalent to getc(stdin).
  3350.  
  3351.         :: NOTE: Refer to the file_pointer manual page for general
  3352.         :: information.
  3353.  
  3354.     INPUTS
  3355.         none
  3356.  
  3357.     RESULTS
  3358.         int c;    character 0 to 255, or EOF (-1) returned from stdin
  3359.  
  3360.     SEE ALSO
  3361.         putc, putchar, fputc, fread, fwrite, getc
  3362.  
  3363.     EXAMPLE
  3364.         /*
  3365.          *  copy stdin to stdout using getchar/putchar. Normally
  3366.          *  one uses fread/fwrite, but I'll save that for the fread
  3367.          *  manual page.
  3368.          * *  Note that I output the initial message to stderr so it
  3369.          *  does not get stuck into stdout in case the user has
  3370.          *  redirected stdout.
  3371.          *
  3372.          *  See getc manual page for equivalent example using 
  3373.          * getc/putc
  3374.          */
  3375.         #include <stdio.h>
  3376.         main()
  3377.         {
  3378.            int c;
  3379.            fputs("Type a couple of lines, then ^\ (EOF)\n",
  3380.               stderr);
  3381.            while ((c = getchar()) != EOF)
  3382.            {
  3383.                putchar(c);
  3384.            }
  3385.            return(0);
  3386.         }
  3387.  
  3388. dice/getcwd                                                      dice/getcwd
  3389.  
  3390.     FUNCTION
  3391.         get current working directory
  3392.  
  3393.     LIBRARY
  3394.         TBA
  3395.  
  3396.     SYNTAX
  3397.         #include <TBA.h>
  3398.         char *path = getcwd(buf, max);
  3399.         non-standard call
  3400.  
  3401.     DESCRIPTION
  3402.         getcwd gets the current working directory and puts it into the
  3403.         specified buffer buf. If buf is NULL it will be malloc'd
  3404.         automatically. The parameter buf is returned (or the malloc'd buffer
  3405.         if you passed NULL for buf). The parameter max specifies the maximum
  3406.         length of the path including the terminating NULL character. NULL is
  3407.         returned if any error occurs (such as malloc failing)
  3408.  
  3409.     INPUTS
  3410.         char *buf;    buffer to place current directory path into or NULL if you
  3411.         want getcwd to allocate one
  3412.  
  3413.         int max;     maximum size of buffer
  3414.  
  3415.     RESULTS
  3416.         char *path;     returns allocated buffer if you passed NULL for buf, else
  3417.         returns the first argument.  Returns NULL on error.
  3418.  
  3419.     SEE ALSO
  3420.         chdir
  3421.  
  3422.     EXAMPLE
  3423.         #include <stdio.h>
  3424.         char buf[512];
  3425.         main(ac, av)
  3426.         int ac; 
  3427.         char *av[];
  3428.         {
  3429.            getcwd(buf, sizeof(buf));
  3430.            printf("Current directory is: %s\n", buf);
  3431.            return(0);
  3432.         }
  3433.  
  3434. dice/getenv                                                      dice/getenv
  3435.  
  3436.     FUNCTION
  3437.         get environment variable
  3438.  
  3439.     LIBRARY
  3440.         TBA
  3441.  
  3442.     SYNTAX
  3443.         #include <TBA.h>
  3444.         char *var = getenv(const char *name);
  3445.  
  3446.     DESCRIPTION
  3447.         getenv searches for and returns the `ENV: enviroment variable
  3448.         requested.  getenv will cache variables so that requesting the same
  3449.         variable repetitously does not allocate a new memory buffer.  getenv
  3450.         allocates a buffer for each variable returned, so you do not have to
  3451.         copy the return value from getenv.  This memory is free'd on program
  3452.         exit.  Do not attempt to free a getenv'd variable!!
  3453.  
  3454.     INPUTS
  3455.         char *name;      Name of enviroment variable, on the Amiga this is not
  3456.         case sensitive. On UNIX systems it is.
  3457.  
  3458.     RESULTS
  3459.         char *var;    Contents of enviroment variable or NULL if the variable
  3460.         could not be found.
  3461.  
  3462.     SEE ALSO
  3463.         TBA
  3464.  
  3465.     EXAMPLE
  3466.         #include <stdio.h>
  3467.         #include h>
  3468.         main(ac, av)
  3469.         int ac;
  3470.         char *av[];
  3471.         {
  3472.            char *dccopts = getenv("DCCOPTS");
  3473.            if (dccopts)
  3474.               printf("DCCOPTS = %s\n", dccopts);
  3475.            else
  3476.               printf("You do not have a DCCOPTS enviroment
  3477.                           variable!\n");
  3478.            return(0);
  3479.         }
  3480.  
  3481. dice/getfnl                                                      dice/getfnl
  3482.  
  3483.     FUNCTION
  3484.         get file name list; scan directory, return list of files that match
  3485.         the optional wildcard.
  3486.  
  3487.     LIBRARY
  3488.         TBA
  3489.  
  3490.     SYNTAX
  3491.         #include <TBA.h>
  3492.         int n = getfnl(pat, buf, bufsize, attr);
  3493.  
  3494.         const char *pat;
  3495.         char *buf;
  3496.         int bufsize;
  3497.         int attr;
  3498.  
  3499.     DESCRIPTION
  3500.         getfnl scans the specified anchored AmigaDOS pattern and fills the
  3501.         specified buffer (up to bufsize bytes) with file names separated by a
  3502.         NULL character (\0), ending the list with a double NULL (\0\0). getfnl
  3503.         returns the number of files/dirs in the buffer or -1 if there is not
  3504.         enough room  The pattern pat is an AmigaDOS pattern such as
  3505.         "df0:#?.c". The parameter buf is a buffer of bufsize bytes.  The
  3506.         parameter attr determines what kinds of files are valid:    0 for
  3507.         normal files only, 1 for files and directories
  3508.  
  3509.         :: NOTE: getfnl exists for compatibility only;  expand_args is a much
  3510.         :: better function function to use if you want a list of files & dirs.
  3511.  
  3512.     INPUTS
  3513.         const char *pat;    pattern to scan for (anchored)
  3514.  
  3515.         char *buf;    buffer to put results in
  3516.  
  3517.         int bufsize;    size of buffer
  3518.  
  3519.         int attr;      attribes (0 or 1)
  3520.  
  3521.     RESULTS
  3522.         int n;    number of file names in buffer or -1 on error
  3523.  
  3524.     SEE ALSO
  3525.         strbpl, wildcard
  3526.  
  3527.     EXAMPLE
  3528.         #include <stdio.h>
  3529.         char Buf[4096];
  3530.         main(ac, av)
  3531.         int ac;
  3532.         char *av[];
  3533.         {
  3534.            int n;
  3535.            if (ac != 2)
  3536.            {
  3537.               puts("Expected an anchored wildcard such as '#?'");
  3538.               exit(1);
  3539.            }
  3540.            n = getfnl(av[1], Buf, sizeof(Buf), 1);
  3541.            {
  3542.               char *ptr = Buf;
  3543.               while (*ptr)
  3544.               {
  3545.                   /*  look for \0\0   */
  3546.                   puts(ptr);
  3547.                   ptr += strlen(ptr) + 1;
  3548.                   /*  skip first \0   */
  3549.               }
  3550.            }
  3551.            return(0);
  3552.         }
  3553.  
  3554. dice/GetHead,GetTail,GetSucc,GetPred    dice/GetHead,GetTail,GetSucc,GetPred
  3555.  
  3556.     FUNCTION
  3557.         get first element in EXEC list;
  3558.         get last element in EXEC list GetSucc;
  3559.         get next element after some element (node)
  3560.         get previous element before some element (node)
  3561.  
  3562.     LIBRARY
  3563.         TBA
  3564.  
  3565.     SYNTAX
  3566.         #include <TBA.h>
  3567.         struct Node *node = GetHead(list);
  3568.         struct Node *node = GetTail(list);
  3569.         struct Node *node = GetSucc(oldNode);
  3570.         struct Node *node = GetPred(oldNode);
  3571.         const struct Node *oldNode;
  3572.         const struct List *list;
  3573.  
  3574.        DESCRIPTION
  3575.         These functions allow scanning of EXEC style lists (which are also
  3576.         useful for many programs having nothing to do with EXEC). GetHead
  3577.         returns the first node in a list or NULL if the list is empty; GetTail
  3578.         returns the last node in a list or NULL if the list is empty; GetSucc
  3579.         returns the next node in a list (given some intermediate  node) or
  3580.         NULL when we reach the end of the list GetPred returns the previous
  3581.         node in a list before some intermediate node or NULL when we reach the
  3582.         beginning of the list
  3583.  
  3584.         :: NOTE: These are DICE functions and do not exist outside of DICE,
  3585.         :: though easily written.
  3586.  
  3587.     INPUTS
  3588.         struct List *list;    list to get head or tail node from
  3589.  
  3590.         struct Node *oldNode;    node from which to get relative successor or
  3591.         predecessor from
  3592.  
  3593.     RESULTS
  3594.         struct Node *node;    returned node or NULL
  3595.  
  3596.     SEE ALSO
  3597.         TBA
  3598.  
  3599.     EXAMPLE
  3600.         /*
  3601.          *  Stupid symbol create/delete/list program.  Note that for
  3602.          *  a real symbol table you want to use hash tables.
  3603.          */
  3604.         #include <lists.h>    /*  non-standard header file  */
  3605.         #include <stdio.h>
  3606.         #include <stdlib.h>
  3607.         #include <string.h>
  3608.         typedef struct List List;
  3609.         typedef struct Node Node;
  3610.         List SymList;
  3611.         void AddSymbol(char *);
  3612.         void DelSymbol(char *);
  3613.         Node *FindSymbol(char *);
  3614.         main()
  3615.         {
  3616.            char buf[256];
  3617.            char symBuf[256];
  3618.            short notDone = 1;
  3619.            NewList(&SymList);
  3620.            puts("(return for help)");
  3621.            while (notDone)
  3622.            {
  3623.               printf("Enter Command: ");
  3624.               fflush(stdout);
  3625.               if (gets(buf) == NULL)
  3626.                  break;
  3627.               switch(buf[0])
  3628.               {
  3629.                  case 'a': if (sscanf(buf + 1, "%s", symBuf) == 1)
  3630.                     AddSymbol(symBuf);
  3631.                     break;
  3632.                  case 'd': if (sscanf(buf + 1, "%s", symBuf) == 1)
  3633.                      DelSymbol(symBuf);
  3634.                      break;
  3635.                  case 'l': { Node *node;
  3636.                       for (node =  GetHead(&SymList); node;
  3637.                       node = GetSucc(node))
  3638.                       puts(node->ln_Name);
  3639.               }
  3640.               break;
  3641.               case 'q': notDone = 0;
  3642.                  break;
  3643.               default: puts("<return>      -help   ");
  3644.                  puts("a name-add symbol");
  3645.                  puts("d name-delete symbol");
  3646.                  puts("l     -list symbols");
  3647.                  puts("q     -quit");
  3648.                  break;
  3649.            }
  3650.         }
  3651.         puts("bye!");
  3652.         return(0);
  3653.         }`
  3654.         void AddSymbol(name)
  3655.         char *name;
  3656.         {
  3657.            Node *node;
  3658.            if (FindSymbol(name))
  3659.            {
  3660.               puts("already exists!");
  3661.               exit(1);
  3662.            }
  3663.            if (node = malloc(sizeof(Node)))
  3664.            {
  3665.               AddTail(&SymList, node);
  3666.               node->ln_Name = strdup(name);
  3667.               /* bad code, not checking */
  3668.               /* for error result!      */
  3669.            }
  3670.         }
  3671.         
  3672.         void DelSymbol(name)
  3673.         char *name;
  3674.         {
  3675.            Node *node;
  3676.            if (node = FindSymbol(name))
  3677.            {
  3678.               Remove(node);   /*  take out of list    */
  3679.               free(node->ln_Name);    /*  free name   */
  3680.               free(node);     /*  free node last      */
  3681.               puts("ok");
  3682.               }
  3683.            else
  3684.            {
  3685.               puts("Couldn't find it!");
  3686.         }
  3687.  
  3688.         }
  3689.         
  3690.         Node * FindSymbol(name)
  3691.         char *name;
  3692.         {
  3693.            Node *node;
  3694.            for (node = GetHead(&SymList); node;
  3695.                  node = GetSucc(node))
  3696.            {
  3697.                 if (strcmp(node->ln_Name, name) == 0)
  3698.                 return(node);
  3699.            }
  3700.            return(NULL);
  3701.         }
  3702.  
  3703. dice/gets                                                          dice/gets
  3704.  
  3705.     FUNCTION
  3706.         get a line from stdin
  3707.  
  3708.     LIBRARY
  3709.         TBA
  3710.  
  3711.     SYNTAX
  3712.         #include <stdio.h>
  3713.         char *ptr = gets(buf);
  3714.         char *buf;
  3715.  
  3716.     DESCRIPTION
  3717.         gets takes a line from stdin returning its first argument (buf) if all
  3718.         went well, NULL if an error or EOF occured. gets stores the line into
  3719.         the specified buffer up to a maximum of 256 characters (includes \0).
  3720.         It is common to  confuse gets, fgets, puts, and fputs.  While gets
  3721.         strips off any newline `'\n' and puts adds one, fgets keeps the
  3722.         newline at the end of the line and fputs does not add one.   gets and
  3723.         puts work on stdin and stdout while fgets and fputs work on arbitrary
  3724.         file pointers.
  3725.  
  3726.         :: NOTE: Refer to the file_pointer manual page for general
  3727.         :: information.
  3728.  
  3729.     INPUTS
  3730.         char *buf;    buffer, must be able to hold 256 characters
  3731.  
  3732.     RESULTS
  3733.         char *ptr;    buf if all is well, or NULL if error or EOF
  3734.  
  3735.     SEE ALSO
  3736.         gets, puts, fputs, fread, getc, fgetc
  3737.  
  3738.     EXAMPLE
  3739.         #include <stdio.h>
  3740.         main()
  3741.         {
  3742.            char buf[256];
  3743.            printf("Enter a line - ");
  3744.            fflush(stdout);
  3745.            if (gets(buf) == NULL)
  3746.               exit(1);
  3747.            printf("Your line was: %s\n", buf);
  3748.            return(0);
  3749.         }
  3750.  
  3751. dice/_GFXBase                                                  dice/_GFXBase
  3752.  
  3753.     FUNCTION
  3754.         auto-open Graphics Library Base
  3755.  
  3756.     LIBRARY
  3757.         TBA
  3758.  
  3759.     SYNTAX
  3760.         TBA
  3761.  
  3762.     DESCRIPTION
  3763.         If the _GFXBase base variable is referenced (i.e. extern) but not
  3764.         declared then _GFXBase will be automatically declared in the gfxlib
  3765.         module of auto.lib. Additionally, auto.lib adds routines to the
  3766.         autoinit and autoexit sequences called by c.a that automatically opens
  3767.         "graphics.library" before _main and closes it after _exit. If the
  3768.         auto-open fails the program will be aborted before _main is ever
  3769.         called. The autoexit routine that closes the library first checks to
  3770.         see if  the base variable is NULL and skips trying to close the
  3771.         library if so.
  3772.  
  3773.         :: NOTE: Programs that use this auto-open feature simply by calling
  3774.         :: graphics library functions without bothering to declare or open the
  3775.         :: library will only compile under DICE.  When compiled with other
  3776.         :: compilers a link error will occur since the linker will not be able
  3777.         :: to find any declared storage for the base variable, only
  3778.         :: references.
  3779.  
  3780.     SEE ALSO
  3781.         TBA
  3782.  
  3783.     EXAMPLE
  3784.         /*
  3785.          *  Example program which just calls a graphics.library
  3786.          *  function without bothering to open the library.
  3787.          */
  3788.         main()
  3789.         {
  3790.            WaitTOF();
  3791.         }
  3792.  
  3793. dice/_IntuitionBase                                      dice/_IntuitionBase
  3794.  
  3795.     FUNCTION
  3796.         auto-open Intuition Base
  3797.  
  3798.     LIBRARY
  3799.         TBA
  3800.  
  3801.     SYNTAX
  3802.         TBA
  3803.  
  3804.     DESCRIPTION
  3805.         If the _IntuitionBase base variable is referenced (i.e. extern) but
  3806.         not declared then _IntuitionBase will be automatically declared in the
  3807.         intlib module of auto.lib. Additionally, auto.lib adds routines to the
  3808.         autoinit and autoexit sequences called by c.a that automatically opens
  3809.         "intuition.library" before _main and closes it after _exit. If the
  3810.         auto-open fails the program will be aborted before _main is ever
  3811.         called. The autoexit routine that closes the library first checks to
  3812.         see if the base variable is NULL and skips trying to close the library
  3813.         if so.
  3814.  
  3815.         :: NOTE:  Programs that use this auto-open feature by simply calling
  3816.         :: graphics library functions without bothering to declare or open the
  3817.         :: library will only compile under DICE.  When compiled with other
  3818.         :: compilers a link error will occur since the linker will not be able
  3819.         :: to find any declared storage for the base variable, only
  3820.         :: references.
  3821.  
  3822.     SEE ALSO
  3823.         TBA
  3824.  
  3825.     EXAMPLE
  3826.         /*
  3827.          *  Example program which just calls an intuition.library
  3828.          *  function without bothering to open the library.
  3829.          */
  3830.         main()
  3831.         {
  3832.            LockIBase();
  3833.            UnlockIBase();
  3834.         }
  3835.  
  3836. dice/isalnum                                                    dice/isalnum
  3837.  
  3838.     FUNCTION
  3839.         check that a character is in the alphanumeric domain
  3840.  
  3841.     LIBRARY
  3842.         TBA
  3843.  
  3844.     SYNTAX
  3845.         #include <TBA.h>
  3846.         int r = isalnum(c);
  3847.         int c;
  3848.  
  3849.         :: NOTE: This is a MACRO if you #include <ctype.h>, a subroutine call
  3850.         :: if you do not.
  3851.  
  3852.     DESCRIPTION
  3853.         isalnum returns non-zero if the character is alphanumeric (a-z, A-Z,
  3854.         0- 9), zero if it is not.
  3855.  
  3856.         :: NOTE When a non-zero value is returned, this value can be anything
  3857.         :: other than zero.  It is not necessarily a 1.  It is guaranteed to
  3858.         :: fit in a short, however, and still remain non-zero. Characters in
  3859.         :: the 128-255 range are valid inputs. Characters less than -1 or
  3860.         :: larger than 255 are illegal and the results will be random.  If you
  3861.         :: are passing a CHAR, you must cast it to an UNSIGNED CHAR first. EOF
  3862.         :: is a valid input an always returns false
  3863.  
  3864.     INPUTS
  3865.         int c;    character that we are checking
  3866.  
  3867.     RESULTS
  3868.         int r;    0 if the check failed, non-zero if the check is true
  3869.  
  3870.     SEE ALSO
  3871.         isalpha, iscntrl, isdigit, isgraph, islower, isprint, ispunct,
  3872.         isspace, isupper, isxdigit, tolower, toupper
  3873.  
  3874.     EXAMPLE
  3875.         TBA
  3876.  
  3877. dice/isalpha                                                    dice/isalpha
  3878.  
  3879.     FUNCTION
  3880.         check that a character is in the alphabetic domain
  3881.  
  3882.     LIBRARY
  3883.         TBA
  3884.  
  3885.     SYNTAX
  3886.         #include <TBA.h>
  3887.         int r = isalpha(c);
  3888.         int c;
  3889.  
  3890.         :: NOTE: This is a MACRO if you #include <ctype.h>, a subroutine call
  3891.         :: if you do not.
  3892.  
  3893.     DESCRIPTION
  3894.         isalpha returns non-zero if the character is a letter in the alphabet
  3895.         (a-z, A-Z), zero if it is not.
  3896.  
  3897.         :: NOTE When a non-zero value is returned, this value can be anything
  3898.         :: other than zero.  It is not necessarily a 1.  It is guaranteed to
  3899.         :: fit in a short, however, and still remain non-zero. characters in
  3900.         :: the 128-255 range are valid inputs. characters less than -1 or
  3901.         :: larger than 255 are illegal and the results will be random.  If you
  3902.         :: are passing a CHAR, you must cast it to an UNSIGNED CHAR first. EOF
  3903.         :: is a valid input an always returns false.
  3904.  
  3905.     INPUTS
  3906.         int c;    character that we are checking
  3907.  
  3908.     RESULTS
  3909.         int r;    0 if the check failed, non-zero if the check is true
  3910.  
  3911.     SEE ALSO
  3912.         isalnum, iscntrl, isdigit, isgraph, islower, isprint, ispunct,
  3913.         isspace, isupper, isxdigit, tolower, toupper
  3914.  
  3915.     EXAMPLE
  3916.         #include <ctype.h>
  3917.         #include <assert.h>
  3918.         
  3919.         main()
  3920.         {
  3921.            assert(isalpha('a'));
  3922.            assert(isalpha('Z'));
  3923.            assert(!isalpha('1'));
  3924.            assert(!isalpha('%'));
  3925.         }
  3926.  
  3927. dice/isatty                                                      dice/isatty
  3928.  
  3929.     FUNCTION
  3930.         Is a file descriptor a TTY?
  3931.  
  3932.     LIBRARY
  3933.         TBA
  3934.  
  3935.     SYNTAX
  3936.         #include <TBA.h>
  3937.         int r = isatty(fd); int fd;
  3938.  
  3939.     DESCRIPTION
  3940.         isatty returns TRUE (1) if the file descriptor is associated with a
  3941.         console, FALSE (0) if not, or -1 if an error condition occurs (such as
  3942.         illegal file descriptor).
  3943.  
  3944.         :: NOTE The standard input (0), standard output (1), and standard
  3945.         :: error (2) can all return different values for isatty depending on
  3946.         :: how the program is redirected.  A program `whose standard in and
  3947.         :: standard out is redirected may still have a standard error that is
  3948.         :: connected to the console. Refer to the file_descriptor manual page
  3949.         :: for general information.  Unlike file pointers and file handles,
  3950.         :: the file descriptor is checked for validity and will simply return
  3951.         :: an error if illegal.
  3952.  
  3953.     INPUTS
  3954.         int fd;  file descriptor
  3955.  
  3956.     RESULTS
  3957.         int r;    result, 1 if a tty, 0 if not, or -1 if error
  3958.  
  3959.     SEE ALSO
  3960.         close, creat, fcntl, fdtofh, getfh, ioctl, lseek, mkdir, open, read,
  3961.         rmdir, unlink, write
  3962.  
  3963.     EXAMPLE
  3964.         TBA
  3965.  
  3966. dice/iscntrl                                                    dice/iscntrl
  3967.  
  3968.     FUNCTION
  3969.         check for a control character
  3970.  
  3971.     LIBRARY
  3972.         TBA
  3973.  
  3974.     SYNTAX
  3975.         #include <TBA.h>
  3976.         int r = iscntrl(c);
  3977.         int c;
  3978.  
  3979.         :: NOTE: This is a MACRO if you #include <ctype.h>, a subroutine call
  3980.         :: if you do not.
  3981.  
  3982.     DESCRIPTION
  3983.         iscntrl returns non-zero if the character is a control character
  3984.         (0-31), zero if it is not.
  3985.  
  3986.         :: NOTE When a non-zero value is returned, this value can be anything
  3987.         :: other than zero.  It is not necessarily a 1.  It is guaranteed to
  3988.         :: fit in a short, however, and still remain non-zero.  Characters in
  3989.         :: the 128-255 range are valid inputs. Characters less than -1 or
  3990.         :: larger than 255 are illegal and the results will be random.  If you
  3991.         :: are passing a CHAR, you must cast it to an UNSIGNED CHAR first. 
  3992.         :: EOF is a valid input an always returns false.
  3993.  
  3994.     INPUTS
  3995.         int c;    character that we are checking
  3996.  
  3997.     RESULTS
  3998.         int r;    0 if the check failed, non-zero if the check is true
  3999.  
  4000.     SEE ALSO
  4001.         isalnum, isalpha, isdigit, isgraph, islower, isprint, ispunct,
  4002.         isspace, isupper, isxdigit, tolower, toupper
  4003.  
  4004.          EXAMPLE
  4005.         #include <ctype.h>
  4006.         #include <assert.h>
  4007.         
  4008.         main()
  4009.         {
  4010.            assert(iscntrl(10));
  4011.            assert(iscntrl(8));
  4012.            assert(!iscntrl('1'));
  4013.            assert(!iscntrl('%'));
  4014.         }
  4015.  
  4016. dice/isdigit                                                    dice/isdigit
  4017.  
  4018.     FUNCTION
  4019.         check if character is a digit
  4020.  
  4021.     LIBRARY
  4022.         TBA
  4023.  
  4024.     SYNTAX
  4025.         #include <TBA.h>
  4026.         int r = isdigit(c);
  4027.         int c;
  4028.  
  4029.         :: NOTE: This is a MACRO if you #include <ctype.h>, a subroutine call
  4030.         :: if you do not.
  4031.  
  4032.     DESCRIPTION
  4033.         isdigit returns non-zero if the character is a digit ('0' through
  4034.         '9'), zero if it is not.
  4035.  
  4036.         :: NOTE: When a non-zero value is returned, this value can be anything
  4037.         :: other than zero.  It is not necessarily a 1.  It is guaranteed to
  4038.         :: fit in a short, however, and still remain non-zero. characters in
  4039.         :: the 128-255 range are valid inputs. characters less than -1 or
  4040.         :: larger than 255 are illegal and the results will be random.  If you
  4041.         :: are passing a CHAR, you must cast it to an UNSIGNED CHAR first. EOF
  4042.         :: is a valid input an always returns false.
  4043.  
  4044.     INPUTS
  4045.         int c;    character that we are checking
  4046.  
  4047.     RESULTS
  4048.         int r;    0 if the check failed, non-zero if the check is true
  4049.  
  4050.     SEE ALSO
  4051.         isalnum, isalpha, iscntrl, isgraph, islower, isprint, ispunct,
  4052.         isspace, isupper, isxdigit, tolower, toupper
  4053.  
  4054.     EXAMPLE
  4055.         TBA
  4056.  
  4057. dice/isgraph                                                    dice/isgraph
  4058.  
  4059.     FUNCTION
  4060.         check for a printable character, excludes the space character
  4061.  
  4062.     LIBRARY
  4063.         TBA
  4064.  
  4065.     SYNTAX
  4066.         #include <TBA.h>
  4067.         int r = isgraph(c);
  4068.         int c;
  4069.  
  4070.         :: NOTE:  This is a MACRO if you #include <ctype.h>, a subroutine call
  4071.         :: if you do not.
  4072.  
  4073.     DESCRIPTION
  4074.         isgraph returns non-zero if the character is printable and not a
  4075.         space, zero otherwise. isgraph is the isprint function but with the
  4076.         space character excluded from the printable set.
  4077.  
  4078.         :: NOTE When a non-zero value is returned, this value can be anything
  4079.         :: other than zero.  It is not necessarily a 1.  It is guaranteed to
  4080.         :: fit in a short, however, and still remain non-zero. characters in
  4081.         :: the 128-255 range are valid inputs. characters less than -1 or
  4082.         :: larger than 255 are ILLEGAL and the results will be random.  If you
  4083.         :: are passing a CHAR, you must cast it to an UNSIGNED CHAR first. EOF
  4084.         :: is a valid input an always returns false.
  4085.  
  4086.     INPUTS
  4087.         int c;    character that we are checking
  4088.  
  4089.     RESULTS
  4090.         int r;    0 if the check failed, non-zero if the check is true
  4091.  
  4092.     SEE ALSO
  4093.         isalnum, isalpha, iscntrl, isdigit, islower, isprint, ispunct,
  4094.         isspace, isupper, isxdigit, tolower, toupper
  4095.  
  4096.       EXAMPLE
  4097.         #include <ctype.h>
  4098.         #include <assert.h>
  4099.         
  4100.         main()
  4101.         {
  4102.            assert(isgraph('^'));
  4103.            assert(isgraph('$'));
  4104.            assert(!isgraph(' '));
  4105.            assert(!isgraph(127));
  4106.         }
  4107.  
  4108. dice/islower                                                    dice/islower
  4109.  
  4110.     FUNCTION
  4111.         check for a lower case alphabetic character
  4112.  
  4113.     LIBRARY
  4114.         TBA
  4115.  
  4116.     SYNTAX
  4117.         #include <TBA.h>
  4118.         int r = islower(c);
  4119.         int c;
  4120.  
  4121.         :: NOTE: This is a MACRO if you #include <ctype.h>, a subroutine call
  4122.         :: if you do not.
  4123.  
  4124.     DESCRIPTION
  4125.         islower returns non-zero if the character is a lower case letter 'a' -
  4126.         'z', zero otherwise.
  4127.  
  4128.         :: NOTE When a non-zero value is returned, this value can be anything
  4129.         :: other than zero.  It is not necessarily a 1.  It is guaranteed to
  4130.         :: fit in a short, however, and still remain non-zero. characters in
  4131.         :: the 128-255 range are valid inputs. characters less than -1 or
  4132.         :: larger than 255 are illegal and the results will be random.  If you
  4133.         :: are passing a CHAR, you must cast it to an UNSIGNED CHAR first. EOF
  4134.         :: is a valid input an always returns false
  4135.  
  4136.     INPUTS
  4137.         int c;    character that we are checking
  4138.  
  4139.     RESULTS
  4140.         int r;    0 if the check failed, non-zero if the check is true
  4141.  
  4142.     SEE ALSO
  4143.         isalnum, isalpha, iscntrl, isdigit, isgraph, isprint, ispunct,
  4144.         isspace, isupper, isxdigit, tolower, toupper
  4145.  
  4146.     EXAMPLE
  4147.         #include <ctype.h>
  4148.         #include <assert.h>
  4149.         
  4150.         main()
  4151.         {
  4152.            assert(islower('a'));
  4153.            assert(islower('g'));
  4154.            assert(!islower('Z'));
  4155.            assert(!islower(127));
  4156.         }
  4157.  
  4158. dice/isprint                                                    dice/isprint
  4159.  
  4160.     FUNCTION
  4161.         check for a printable character, includes the space character
  4162.  
  4163.     LIBRARY
  4164.         TBA
  4165.  
  4166.     SYNTAX
  4167.         #include <TBA.h>
  4168.         int r = isprint(c);
  4169.         int c;
  4170.  
  4171.         :: NOTE: This is a MACRO if you #include <ctype.h>, a subroutine call
  4172.         :: if you do not.
  4173.  
  4174.     DESCRIPTION
  4175.         isprint returns non-zero if the character is printable, zero
  4176.         otherwise. isprint is the isgraph function but with the space
  4177.         character included in the printable set.
  4178.  
  4179.         :: NOTE: When a non-zero value is returned, this value can be anything
  4180.         :: other than zero.  It is not necessarily a 1.  It is guaranteed to
  4181.         :: fit in a short, however, and still remain non-zero. characters in
  4182.         :: the 128-255 range are valid inputs. characters less than -1 or
  4183.         :: larger than 255 are illegal and the results will be random.  If you
  4184.         :: are passing a CHAR, you must cast it to an UNSIGNED CHAR first. EOF
  4185.         :: is a valid input an always returns false
  4186.  
  4187.     INPUTS
  4188.         int c;    character that we are checking
  4189.  
  4190.     RESULTS
  4191.         int r;    0 if the check failed, non-zero if the check is true
  4192.  
  4193.     SEE ALSO
  4194.         isalnum, isalpha, iscntrl, isdigit, isgraph, islower, ispunct,
  4195.         isspace, isupper, isxdigit, tolower, toupper
  4196.  
  4197.     EXAMPLE
  4198.         #include <ctype.h>
  4199.         #include <assert.h>
  4200.         
  4201.         main()
  4202.         {
  4203.            assert(isprint(' '));
  4204.            assert(isprint('^'));
  4205.            assert(!isprint(23));
  4206.            assert(!isprint(127));
  4207.         }
  4208.  
  4209. dice/isupper                                                    dice/isupper
  4210.  
  4211.     FUNCTION
  4212.         check for an upper case alphabetic character
  4213.  
  4214.     LIBRARY
  4215.         TBA
  4216.  
  4217.     SYNTAX
  4218.         #include <TBA.h>
  4219.         int r = isupper(c);
  4220.         int c;
  4221.  
  4222.         :: NOTE:  This is a MACRO if you #include <ctype.h>, a subroutine call
  4223.         :: if you do not.
  4224.  
  4225.     DESCRIPTION
  4226.         isuppern returns non-zero if the character is an upper case letter 'A'
  4227.         -'Z', zero otherwise.
  4228.  
  4229.         :: NOTE: When a non-zero value is returned, this value can be anything
  4230.         :: other than zero.  It is not necessarily a 1.  It is guaranteed to
  4231.         :: fit in a short, however, and still remain non-zero.  Characters in
  4232.         :: the 128-255 range are valid inputs. characters less than -1 or
  4233.         :: larger than 255 are illegal and the results will be random.  If you
  4234.         :: are passing a CHAR, you must cast it to an UNSIGNED CHAR first. EOF
  4235.         :: is a valid input an always returns false.
  4236.  
  4237.     INPUTS
  4238.         int c;    character that we are checking
  4239.  
  4240.     RESULTS
  4241.         int r;    0 if the check failed, non-zero if the check is true
  4242.  
  4243.     SEE ALSO
  4244.         isalnum, isalpha, iscntrl, isdigit, isgraph, islower, isprint,
  4245.         ispunct, isspace, isxdigit, tolower, toupper
  4246.  
  4247.     EXAMPLE
  4248.         #include <ctype.h>
  4249.         #include <assert.h>
  4250.         
  4251.         main()
  4252.         {
  4253.            assert(isupper('A'));
  4254.            assert(isupper('G'));
  4255.            assert(!isupper('z'));
  4256.            assert(!isupper(127));
  4257.         }
  4258.  
  4259. dice/isxdigit                                                  dice/isxdigit
  4260.  
  4261.     FUNCTION
  4262.         check for a character representable as a hexadecimal digit
  4263.  
  4264.     LIBRARY
  4265.         TBA
  4266.  
  4267.     SYNTAX
  4268.         #include <TBA.h>
  4269.         int r = isxdigit(c);
  4270.         int c;
  4271.  
  4272.         :: NOTE: This is a MACRO if you #include <ctype.h>, a subroutine call
  4273.         :: if you do not.
  4274.  
  4275.     DESCRIPTION
  4276.         isxdigit returns non-zero if the character represents a hexadecimal
  4277.         digit '0' - '9', 'a' - 'f', or 'A' - 'F', zero otherwise.
  4278.  
  4279.         :: NOTE: When a non-zero value is returned, this value can be anything
  4280.         :: other than zero.  It is not necessarily a 1.  It is guaranteed to
  4281.         :: fit in a short, however, and still remain non-zero.  Characters in
  4282.         :: the 128-255 range are valid inputs. characters less than -1 or
  4283.         :: larger than 255 are illegal and the results will be random.  If you
  4284.         :: are passing a CHAR, you must cast it to an UNSIGNED CHAR first. EOF
  4285.         :: is a valid input an always returns false.
  4286.  
  4287.     INPUTS
  4288.         int c;    character that we are checking
  4289.  
  4290.     RESULTS
  4291.         int r;    0 if the check failed, non-zero if the check is true
  4292.  
  4293.     SEE ALSO
  4294.         isalnum, isalpha, iscntrl, isdigit, isgraph, islower, isprint,
  4295.         ispunct, isspace, isupper, tolower, toupper
  4296.  
  4297.     EXAMPLE
  4298.         #include <ctype.h>
  4299.         #include <assert.h>
  4300.         
  4301.         main()
  4302.         {
  4303.            assert(isxdigit('9'));
  4304.            assert(isxdigit('0'));
  4305.            assert(isxdigit('A'));
  4306.            assert(isxdigit('d'));
  4307.            assert(!isxdigit('x'));
  4308.            assert(!isxdigit(27));
  4309.         }
  4310.  
  4311. dice/ioctl                                                        dice/ioctl
  4312.  
  4313.     FUNCTION
  4314.         IO control on file descriptor
  4315.  
  4316.     LIBRARY
  4317.         TBA
  4318.  
  4319.     SYNTAX
  4320.         #include <TBA.h>
  4321.         int r = ioctl(fd, req, parg1, parg2);
  4322.         int fd;
  4323.         int req;
  4324.         int *parg1;
  4325.         int *parg2;
  4326.  
  4327.     DESCRIPTION
  4328.         ioctl executes an IO control on the file descriptor.  Currently no IO
  4329.         controls are implemented.
  4330.  
  4331.     INPUTS
  4332.         int fd;    file descriptor
  4333.  
  4334.         int req;    request from <ioctl.h>
  4335.  
  4336.         int *parg1;    address of argument #1
  4337.  
  4338.         int *parg2;    address of argument #2
  4339.  
  4340.     RESULTS
  4341.         int r;    result, error if < 0.
  4342.  
  4343.     SEE ALSO
  4344.         close, creat, fcntl, fdtofh, getfh, isatty, lseek, mkdir, open, read,
  4345.         rmdir,
  4346.  
  4347.         unlink, write
  4348.  
  4349.     EXAMPLE
  4350.         TBA
  4351.  
  4352. dice/localtime                                                dice/localtime
  4353.  
  4354.     FUNCTION
  4355.         convert time into broken down time
  4356.  
  4357.     LIBRARY
  4358.         TBA
  4359.  
  4360.     SYNTAX
  4361.         #include <TBA.h>
  4362.         struct tm *tp = localtime(&t); 
  4363.         time_t t;
  4364.  
  4365.     DESCRIPTION
  4366.         localtime takes the address of a time_t variable and breaks up the
  4367.         time into component parts, storing them in a static tm structure.  The
  4368.         address of this structure is returned.  Since the broken up time is
  4369.         stored into a static structure, the structure will get overwritten on
  4370.         the next call to localtime. The fields of the tm structure are:
  4371.  
  4372.         struct tm {
  4373.                int tm_sec;     /*  0-59    */
  4374.                int tm_min;     /*  0-59    */
  4375.                int tm_hour;    /*  0-23    */
  4376.                int tm_mday;    /*  1-31    */
  4377.                int tm_mon;     /*  0-11    */
  4378.                int tm_year;    /*  n+1900  */
  4379.                int tm_wday;    /*  (sun)0-6*/
  4380.                int tm_yday;    /*  0-366   */
  4381.                int tm_isdst;   /*  daylight svings time flag
  4382.                                 * (not impl by DICE)
  4383.                                 */
  4384.         };
  4385.  
  4386.     INPUTS
  4387.         time_t *t;    pointer to a time_t
  4388.  
  4389.     RESULTS
  4390.         struct tm *tp;      pointer to a struct tm structure filled out according
  4391.         to the
  4392.  
  4393.              passed time.
  4394.  
  4395.     SEE ALSO
  4396.         time, asctime, strftime, ctime, clock
  4397.  
  4398.     EXAMPLE
  4399.         /*
  4400.          *  Note that it is much easier to format time/date strings
  4401.          *  with strftime().
  4402.          */
  4403.         #include <stdio.h>
  4404.         #include <time.h> 
  4405.         main()
  4406.         {
  4407.            time_t t = time(NULL);
  4408.            struct tm *tp = localtime(&t);
  4409.            printf("The time is %02d:%02d:%02d\n", tp->tm_hour,
  4410.                     tp->tm_min, tp->tm_sec);
  4411.            return(0);
  4412.         }
  4413.  
  4414. dice/LockAddr,LockAddrB,TryLockAddr,TryLockAddrB,UnlockAddr,UnlockAddrB
  4415.  
  4416.     FUNCTION
  4417.         LockAddr: Gain Exclusive, Fast semaphore (bit 0);
  4418.         LockAddrB: Gain Exclusive, Fast semaphore (bit n 0-7);
  4419.         TryLockAddr: Non- Blocking version of LockAddr;
  4420.         TryLockAddrB: Non-Blocking version of LockAddrB;
  4421.         UnlockAddr: Release exclusive semaphore, bit 0;
  4422.         UnlockAddrB: Release exclusive semaphore, bit n 0-7
  4423.  
  4424.     LIBRARY
  4425.         TBA
  4426.  
  4427.     SYNTAX
  4428.         #include <TBA.h>
  4429.         void LockAddr(lck);
  4430.         void LockAddrB(bitno, lck);
  4431.         int r = TryLockAddr(lck);
  4432.         int r = TryLockAddrB(bitno, lck);
  4433.         void UnlockAddr(lck);
  4434.         void UnlockAddrB(bitno, lck);
  4435.         long lck[2];
  4436.  
  4437.     DESCRIPTION
  4438.         These are custom DICE functions used for inter-task locking semaphores
  4439.         in programs that need such functions.  These routines are somewhat
  4440.         faster than standard Amiga semaphore routines and take less memory,
  4441.         though at the cost of DICE specific. To use an inter-task lock one
  4442.         first initializes an lck array to 0's. The entry long lck[2]; is an
  4443.         array of two longwords that the lock routines will use to do their
  4444.         stuff.  This array should be zero'd only once at program
  4445.         initialization time (the master task before any other tasks are
  4446.         created that use it). Each lck array may hold up to 8 locks, hence the
  4447.         LockAddrB calls. The non-B calls use lock #0 for simplicity.  For
  4448.          simplicity we will only discuss non-B calls.
  4449.         To gain a lock you may call LockAddr with the address of the lck array
  4450.         (which, being an array, does not need the & in the call). This routine
  4451.         will not return until the lock can be obtained. You may also use
  4452.         TryLockAddr to attempt to gain a lock. The return value is:    -1 if
  4453.         the command is unable to obtain the lock (that is, it is in use),  1
  4454.         if the lock has been obtained.  To release an obtained lock you call
  4455.         UnlockAddr(lck).
  4456.  
  4457.         || WARNING!  DO NOT RELEASE A LOCK YOU DO NOT HAVE!
  4458.  
  4459.     INPUTS
  4460.         long *lck;    a pointer to two longwords, initially zero'd
  4461.  
  4462.         -int bitno;    lock # ... up to 8 independant locks exist for each lck
  4463.         structure
  4464.  
  4465.     RESULTS
  4466.         int r;    (TryLock only), -1 on failure, 1 on success.
  4467.  
  4468.     SEE ALSO
  4469.         TBA
  4470.  
  4471.     EXAMPLE
  4472.         /*
  4473.          *  This program obtains a lock based at a public message
  4474.          *  port and holds it for ten seconds before releasing it.
  4475.          *  The public message port is left in memory (but only
  4476.          *  exists once no matter how many programs you run).
  4477.          *
  4478.          *  To test locking, open up two or more CLI's and run the
  4479.          *  program simultaniously (or as close as your fingers can
  4480.          *  make it) two or more times.  Only one program will
  4481.          *  'have' the lock at a time.
  4482.          *
  4483.          *  we use AllocMem() so the port survives the program
  4484.          */
  4485.         
  4486.         #include <exec/types.h>
  4487.         #include <exec/ports.h>
  4488.         #include <exec/memory.h>
  4489.         #include <stdio.h>
  4490.         #include <stdlib.h>
  4491.         #include <assert.h>
  4492.         
  4493.         typedef struct
  4494.         {
  4495.            struct MsgPort Port;
  4496.            long   Lock[2];
  4497.         }
  4498.         MyPort;
  4499.         
  4500.         extern void *FindPort();
  4501.         extern void *CreatePort();
  4502.         extern void *AllocMem();
  4503.         MyPort *Port;
  4504.         short HaveLock;
  4505.         
  4506.         int brk()
  4507.         {
  4508.            if (HaveLock)
  4509.            UnlockAddr(Port->Lock);
  4510.            return(1);      /*  abort   */
  4511.         }
  4512.         
  4513.         main()
  4514.         {
  4515.            char *portName = "Lock-Test";
  4516.            onbreak(brk);
  4517.            Forbid();
  4518.            if ((Port = FindPort(portName)) == NULL)
  4519.            {
  4520.               MyPort *port;
  4521.               port = AllocMem(sizeof(MyPort) + strlen(portName) +
  4522.                          1, MEMF_PUBLIC | MEMF_CLEAR); assert(port);
  4523.               port->Port.mp_Node.ln_Name = (char *)(port + 1);
  4524.               port->Port.mp_Node.ln_Type = NT_MSGPORT;
  4525.               strcpy(port->Port.mp_Node.ln_Name, portName);
  4526.               AddPort(port);
  4527.               Port = port;
  4528.            }
  4529.            Permit();
  4530.            puts("getting lock");
  4531.            LockAddr(Port->Lock);
  4532.            HaveLock = 1;
  4533.            puts("Got the lock!, sleeping for 10 seconds");
  4534.            sleep(10);
  4535.            UnlockAddr(Port->Lock);
  4536.            HaveLock = 0;
  4537.            puts("released lock");
  4538.            return(0);
  4539.         }
  4540.  
  4541. dice/log,flog                                                  dice/log,flog
  4542.  
  4543.     FUNCTION
  4544.         log: return the log of the double quantity, base e;
  4545.         flog: return the log of the float quantity, base e
  4546.  
  4547.     LIBRARY
  4548.         TBA
  4549.  
  4550.     SYNTAX
  4551.         #include <math.h>
  4552.         double a = log(b);
  4553.         double b;
  4554.         float  c = flog(d);
  4555.         float  d;
  4556.  
  4557.     DESCRIPTION
  4558.         The former command returns the log of the double quantity, base e;  
  4559.         the latter returns the log of the float quantity, base e.
  4560.  
  4561.     INPUTS
  4562.         double b;    double floating point value float d; float floating point
  4563.         value
  4564.  
  4565.     RESULTS
  4566.         double a;    result double floating point value float c; result float 
  4567.         floating point value
  4568.  
  4569.     SEE ALSO
  4570.         acos, asin, atan, cos, exp, fabs, log10, pow, sin, sqrt, tan facos,
  4571.         fasin, ...
  4572.  
  4573.     EXAMPLE
  4574.         TBA
  4575.  
  4576. dice/log10,flog10                                          dice/log10,flog10
  4577.  
  4578.     FUNCTION
  4579.         log10: return the log of the double quantity, base 10 
  4580.         flog10: return the log of the float quantity, base 10
  4581.  
  4582.     LIBRARY
  4583.         TBA
  4584.  
  4585.     SYNTAX
  4586.         #include <math.h>
  4587.         double a = log10(b);
  4588.         double b;
  4589.         float  c = flog10(d);
  4590.         float  d;
  4591.  
  4592.     DESCRIPTION
  4593.         log10 returns the log of a double quantity, base 10; flog10 returns
  4594.         the log of the floating point quantity, base 10.
  4595.  
  4596.     INPUTS
  4597.         double b;    double floating point value
  4598.  
  4599.         float d;       float floating point value
  4600.  
  4601.     RESULTS
  4602.         double a;    result double floating point value
  4603.  
  4604.         float c;     result float  floating point value
  4605.  
  4606.     SEE ALSO
  4607.         acos, asin, atan, cos, exp, fabs, log, pow, sin, sqrt, tan facos,
  4608.         fasin, ...
  4609.  
  4610.     EXAMPLE
  4611.         /*
  4612.          *  compile with the math library -lm
  4613.          */
  4614.         #include <math.h>
  4615.         #include <stdio.h>
  4616.         main()
  4617.         {
  4618.            {
  4619.               double a = log10(0.25);
  4620.               printf("log10 0.25 = %lf\n", a); /* -0.6021 */
  4621.            }
  4622.            {
  4623.               /*  less accuracy   */
  4624.               float a = flog10(0.25);
  4625.               printf("log10 0.25 = %lf\n", (double)a);
  4626.            }
  4627.            return(0);
  4628.         }
  4629.  
  4630. dice/lseek                                                        dice/lseek
  4631.  
  4632.     FUNCTION
  4633.         seek within a file descriptor
  4634.  
  4635.     LIBRARY
  4636.         TBA
  4637.  
  4638.     SYNTAX
  4639.         #include <TBA.h>
  4640.         long newpos = lseek(fd, offset, how)
  4641.         int fd; 
  4642.         long offset; 
  4643.         int how;
  4644.  
  4645.     DESCRIPTION
  4646.         lseek changes where the file descriptor points to within the open
  4647.         file.  You may specify an offset relative to the  beginning of the
  4648.         file, the current position in the file, or the end of the file:
  4649.  
  4650.         Val, Purpose
  4651.  
  4652.         0, absolute offset (relative to the beginning of the file)
  4653.  
  4654.         1, offset relative to the current position in the file
  4655.  
  4656.         2, offset relative to the end of the file
  4657.  
  4658.         Negative offsets may be specified when relative modes are used. The
  4659.         function lseek returns the new position in the file relative to the
  4660.         beginning of the file (i.e. an absolute offset).
  4661.  
  4662.         :: NOTE offsets are relative the how.  So, for example, if you want to
  4663.         :: seek to the fourth character from the end of the file you would
  4664.         :: lseek(fd, -4L, 2); refer to the file_descriptor manual page for
  4665.         :: general information.  Unlike file pointers and file handles, the
  4666.         :: file descriptor is checked for validity and will simply return an
  4667.         :: error if illegal.
  4668.  
  4669.     INPUTS
  4670.         int fd;    file descriptor
  4671.  
  4672.         long offset;    offset relative to how
  4673.  
  4674.         int how;     0 = rel beginning, 1 = rel middle, 2 = rel end
  4675.  
  4676.     RESULTS
  4677.         int newpos;    new position in file (absolute) or < 0 if error
  4678.  
  4679.     SEE ALSO
  4680.         close, creat, fcntl, fdtofh, getfh, ioctl, isatty, mkdir, open, read,
  4681.         rmdir, unlink, write
  4682.  
  4683.     EXAMPLE
  4684.         #include <fcntl.h>
  4685.         
  4686.         main()
  4687.         {
  4688.            int fd;
  4689.            fd = open("t:xx", O_CREAT|O_TRUNC|O_RDWR);
  4690.            if (fd >= 0)
  4691.            {
  4692.               write(fd, "0123456789", 10);
  4693.               lseek(fd, -1L, 1);
  4694.               write(fd, "J", 1);    /*  overwrites the 9    */
  4695.               lseek(fd, -1L, 1);
  4696.               write(fd, "j", 1);    /*  overwrites the J    */
  4697.               lseek(fd, -4L, 2);  /*  position over the 6 */
  4698.               write(fd, "g", 1);   /*  overwrite with g, now over
  4699.                                  *  the 7
  4700.                                  */
  4701.               lseek(fd, 0L, 0);   /*  position over the 0 */
  4702.               write(fd, "a", 1);
  4703.               close(fd);
  4704.            }
  4705.            else
  4706.            {
  4707.               puts("Unable to create T:xx");
  4708.            }
  4709.         }
  4710.  
  4711.         `
  4712.  
  4713.         1> testprg
  4714.         1> type t:xx a12345g78j
  4715.         1>
  4716.  
  4717. dice/_MathBase                                                dice/_MathBase
  4718.  
  4719.     FUNCTION
  4720.         auto-open Math Base
  4721.  
  4722.     LIBRARY
  4723.         TBA
  4724.  
  4725.     DESCRIPTION
  4726.         If the _MathBase base variable is referenced (i.e. extern) but not
  4727.         declared then _MathBase will be automatically declared in the mathlib
  4728.         module of auto.lib.  Additionally, auto.lib adds routines to the
  4729.         autoinit and autoexit sequences called by c.a that automatically opens
  4730.         "math.library" before _main and closes it after _exit. If the
  4731.         auto-open fails the program will be aborted before _main is ever
  4732.         called. The autoexit routine that closes the library first checks to
  4733.         see if the base variable is NULL and skips trying to close the library
  4734.         if so.
  4735.  
  4736.         :: NOTE:  DICE uses the autoinit feature to automatically open and
  4737.         :: close floating point libraries that are indirectly referenced by fp
  4738.         :: operations.
  4739.  
  4740.     SEE ALSO
  4741.         TBA
  4742.  
  4743.     EXAMPLE
  4744.         TBA
  4745.  
  4746. dice/_MathIeeeDoubBasBase                          dice/_MathIeeeDoubBasBase
  4747.  
  4748.     FUNCTION
  4749.         Auto-Open Math Library Base
  4750.  
  4751.     LIBRARY
  4752.         TBA
  4753.  
  4754.     DESCRIPTION
  4755.         If the _MathIeeeDoubBasBase base variable is referenced (i.e. extern)
  4756.         but not declared then _MathIeeeDoubBasBase will be automatically
  4757.         declared in the ieeelib module of auto.lib.  Additionally, auto.lib
  4758.         adds routines to the autoinit and autoexit sequences called by c.a
  4759.         that automatically opens "mathieeedoubbas.library" before _main and 
  4760.         closes it after _exit.  If the auto-open fails the program will be
  4761.         aborted before _main is ever called. The autoexit routine that closes
  4762.         the library first checks to see if the base variable is NULL and skips
  4763.         trying to close the library if so.
  4764.  
  4765.         :: NOTE: DICE uses the autoinit feature to automatically open and
  4766.         :: close floating point libraries that are indirectly referenced by fp
  4767.         :: operations.
  4768.  
  4769.     SEE ALSO
  4770.         TBA
  4771.  
  4772.     EXAMPLE
  4773.         #include <stdlib.h>
  4774.         main()
  4775.         {
  4776.            double d;
  4777.            d = atof("1.234");
  4778.         }
  4779.  
  4780. dice/_MathIeeeDoubTransBase                      dice/_MathIeeeDoubTransBase
  4781.  
  4782.     FUNCTION
  4783.         auto-open TBA
  4784.  
  4785.     LIBRARY
  4786.         TBA
  4787.  
  4788.     DESCRIPTION
  4789.         The _MathIeeeDoubTransBase base variable is referenced (i.e. extern)
  4790.         but not declared then _MathIeeeDoubTransBase will be automatically
  4791.         declared in the ieeetranlib module of auto.lib.  Additionally,
  4792.         auto.lib adds routines to the autoinit and autoexit sequences called
  4793.         by c.a that automatically opens "mathieeedoubtrans.library" before
  4794.         _main and closes it after _exit. If the auto-open fails the program
  4795.         will be aborted before _main is ever called. The autoexit routine that
  4796.         closes the library first checks to see if the base variable is NULL
  4797.         and skips trying to close the library if so.
  4798.  
  4799.         :: NOTE: DICE uses the autoinit feature automatically to open and
  4800.         :: close floating point libraries that are indirectly referenced by fp
  4801.         :: operations.
  4802.  
  4803.     INPUTS
  4804.         TBA
  4805.  
  4806.     RESULTS
  4807.         TBA
  4808.  
  4809.     SEE ALSO
  4810.         TBA
  4811.  
  4812.     EXAMPLE
  4813.         #include <stdlib.h>
  4814.         main()
  4815.         {
  4816.            double d;
  4817.            d = atof("1.234");
  4818.         }
  4819.  
  4820. dice/_MathTransBase                                      dice/_MathTransBase
  4821.  
  4822.     FUNCTION
  4823.         auto-open Math Library Base
  4824.  
  4825.     LIBRARY
  4826.         TBA
  4827.  
  4828.     DESCRIPTION
  4829.         If the _MathTransBase base variable is referenced (i.e. extern) but
  4830.         not declared then _MathTransBase will be automatically declared in the
  4831.         mathlib module of auto.lib.  Additionally, auto.lib adds routines to
  4832.         the autoinit and autoexit sequences called by c.a that automatically
  4833.         opens "mathtrans.library" before _main and closes it after _exit.  If
  4834.         the auto-open fails the program will be aborted before _main is ever
  4835.         called.  The autoexit routine that closes the library first checks to
  4836.         see if the base variable is NULL and skips trying to close the library
  4837.         if so.
  4838.  
  4839.         :: NOTE: DICE uses the autoinit feature automatically to open and
  4840.         :: close floating point libraries that are indirectly referenced by fp
  4841.         :: operations.
  4842.  
  4843.     SEE ALSO
  4844.         TBA
  4845.  
  4846.     EXAMPLE
  4847.         #include <stdlib.h>
  4848.         #include <math.h>
  4849.         
  4850.         main()
  4851.         {
  4852.            float f;
  4853.            f = flog(10.0);
  4854.         }
  4855.  
  4856. dice/main                                                          dice/main
  4857.  
  4858.     FUNCTION
  4859.         main program entry
  4860.  
  4861.     LIBRARY
  4862.         TBA
  4863.  
  4864.     SYNTAX
  4865.         #include <TBA.h>
  4866.         int main(int argc, char **argv)
  4867.         {
  4868.  
  4869.            /* your main routine goes here */
  4870.         }
  4871.  
  4872.     DESCRIPTION
  4873.         The main routine is the entry point called after normal initialization
  4874.         of c.lib and the program enviroment is done by the startup module
  4875.         (c.o) and _main routine (in c.lib).  Under ANSI C main is expected to
  4876.         return an integer exit code. You can no longer simply fall through
  4877.         without returning any value.  Returning an exit code from your main
  4878.         routine is exactly the same as exiting with it.
  4879.  
  4880.         :: NOTE: Any program run from the WORKBENCH uses a different access
  4881.         :: point. Specifically, a program run from the WORKBENCH will run
  4882.         :: wbmain instead of main.  Please refer to the manual  page for
  4883.         :: wbmain for WORKBENCH operation.
  4884.  
  4885.         If you do not supply a wbmain a dummy wbmain will be supplied by the
  4886.         library which simply exits out of the program.
  4887.  
  4888.     INPUTS
  4889.         int argc;       number of arguments
  4890.  
  4891.         char *argv;          array pointer to arguments
  4892.  
  4893.     RESULTS
  4894.         none
  4895.  
  4896.     SEE ALSO
  4897.         wbmain, _main, exit, _exit
  4898.  
  4899.     EXAMPLE
  4900.         #include <stdio.h>
  4901.         
  4902.         int main(ac, av)
  4903.         int ac; char **av;
  4904.         {
  4905.            int i;
  4906.            for (i = 0; i < ac; ++i)
  4907.            {
  4908.               printf("Arg #%d = %s\n", i, av[i]);
  4909.            }
  4910.            return(0);
  4911.         }
  4912.         ` @VERBATIM =  1> sampleprogram this is a test
  4913.         Arg #0 = sampleprogram
  4914.         Arg #1 = this
  4915.         Arg #2 = is
  4916.         Arg #3 = a
  4917.         Arg #4 = test
  4918.         1>
  4919.  
  4920. dice/_main                                                        dice/_main
  4921.  
  4922.     FUNCTION
  4923.         main program entry, bypass standard c.lib initialization
  4924.  
  4925.     LIBRARY
  4926.         TBA
  4927.  
  4928.     SYNTAX
  4929.         #include <TBA.h>
  4930.         void _main(int arglen, char *argptr)
  4931.         {
  4932.  
  4933.         /* your main routine goes here */
  4934.  
  4935.         }
  4936.  
  4937.     DESCRIPTION
  4938.         The _main entry point is called by the startup module (c.o).  Normally
  4939.         _main is part of c.lib and does stdio and other initialization before
  4940.         calling the user main routine. _main is responsible for opening the
  4941.         stderr channel as well.  However, if you specify your own _main you
  4942.         will overide the c.lib version.  Normally you either fall through or
  4943.         _exit from _main. A programmable can use the _main entry point when
  4944.         the executable uses nothing but system library routines.  That is, you
  4945.         make no calls to stdio functions such as puts, printf, etc., to low
  4946.         level IO routines such as open, close, read, etc., or malloc or any
  4947.         routine that uses malloc. Self contained routines such as strcpy may
  4948.         still be called, and, of course, you may open any libraries you wish
  4949.         and make library calls.  Since the auto-library openning and closing
  4950.         is done by the startup module (c.o), "dos.library" will still be
  4951.         opened for you automatically if you make any DOS calls.
  4952.  
  4953.         Using the _main entry point usually results in a substantially smaller
  4954.         executable because stdio and other library routines referenced by the
  4955.         c.lib. _main and exit are never referenced and thus never become part
  4956.         of the executable.  It is NOT SUGGESTED that beginning C programmers
  4957.         use the _main entry point.
  4958.  
  4959.         :: NOTE: _main is called by the startup module whether the program was
  4960.         :: run from the CLI or the WORKBENCH.  You must detect which yourself
  4961.         :: and also deal with the WORKBENCH message yourself.
  4962.  
  4963.     INPUTS
  4964.         TBA
  4965.  
  4966.     RESULTS
  4967.         TBA
  4968.  
  4969.     SEE ALSO
  4970.         _exit, main, exit
  4971.  
  4972.     EXAMPLE
  4973.         /*
  4974.          *  This program comes to approximately a 552 byte
  4975.          *  executable
  4976.          */
  4977.         _main()
  4978.         {
  4979.            Write(Output(), "UG!\n", 4);
  4980.            _exit(1);
  4981.         }
  4982.  
  4983. dice/malloc                                                      dice/malloc
  4984.  
  4985.     FUNCTION
  4986.         allocate memory, the memory is NOT automatically cleared
  4987.  
  4988.     LIBRARY
  4989.         TBA
  4990.  
  4991.     SYNTAX
  4992.         #include <TBA.h>
  4993.         void *ptr = malloc(bytes);
  4994.         size_t bytes;
  4995.  
  4996.     DESCRIPTION
  4997.         malloc allocates the specified number of bytes of memory. The returned
  4998.         pointer is longword aligned; malloc returns NULL if the memory could
  4999.         not be allocated.
  5000.  
  5001.         :: NOTE: Unlike calloc, malloc does not zero the memory before it
  5002.         :: returns.
  5003.  
  5004.     INPUTS
  5005.         size_t bytes;     number of bytes to allocate
  5006.  
  5007.     RESULTS
  5008.         void *ptr;     pointer to base of allocated memory.
  5009.  
  5010.             The memory is not zero'd.
  5011.  
  5012.     SEE ALSO
  5013.         calloc, strdup
  5014.  
  5015.     EXAMPLE
  5016.         TBA
  5017.  
  5018. dice/memcmp                                                      dice/memcmp
  5019.  
  5020.     FUNCTION
  5021.         compare two memory buffers (ANSI)
  5022.  
  5023.     LIBRARY
  5024.         TBA
  5025.  
  5026.     SYNTAX
  5027.         #include <TBA.h>
  5028.         int r = memcmp(s1, s2, bytes)
  5029.         void *s1;
  5030.         void *s2;
  5031.         size_t bytes;
  5032.  
  5033.     DESCRIPTION
  5034.         memcmp compares two memory buffers.  A byte by byte unsigned
  5035.         comparison is done.  When a comparison fails and the byte in s1 is
  5036.         less than the byte in s2 then -1 is returned.  If the byte in s1 is
  5037.         greater than the byte in s2 then 1 is returned.  If the count is
  5038.         exhausted and all comparisons succeed then 0 is returned indicating
  5039.         the two buffers are the same.
  5040.  
  5041.     INPUTS
  5042.         void *s1;     pointer to first buffer
  5043.  
  5044.         void *s2;     pointer to second buffer
  5045.  
  5046.         size_t bytes;     size of each buffer
  5047.  
  5048.     RESULTS
  5049.         int r;     -1 if buf s1 < buf s2, 0 if buf s1 == buf s2, 1 if buf s1 >
  5050.         buf s2.
  5051.  
  5052.     SEE ALSO
  5053.         memset, setmem, bzero, clrmem, bcopy, bcmp, movmem, memcpy, memmove
  5054.  
  5055.     EXAMPLE
  5056.         #include <stdlib.h>
  5057.         #include <assert.h>
  5058.         
  5059.         main()
  5060.         {
  5061.            unsigned char buf1[4];
  5062.            unsigned char buf2[4];
  5063.            int r;
  5064.            buf1[0] = 0;
  5065.            buf2[0] = 0;
  5066.            buf1[1] = 10;
  5067.            buf2[1] = 10;
  5068.            buf1[2] = 15;
  5069.            buf2[2] = 15;
  5070.            buf1[3] = 4;
  5071.            buf2[3] = 4;
  5072.            r = memcmp(buf1, buf2, 4);
  5073.            assert(r == 0);
  5074.            buf1[2] = 12;
  5075.            r = memcmp(buf1, buf2, 4);
  5076.            assert(r < 0);
  5077.            buf1[2] = 200;
  5078.            r = memcmp(buf1, buf2, 4);
  5079.            assert(r > 0);
  5080.            return(0);
  5081.         }
  5082.  
  5083. dice/memcpy,memmove,movmem,bcopy            dice/memcpy,memmove,movmem,bcopy
  5084.  
  5085.     FUNCTION
  5086.         memcopy: copy memory, ANSI, does not work with overlapped memory
  5087.          buffers;
  5088.         memmov: copy memory, ANSI, works with overlapped memory buffers;
  5089.         movmem: copy memory works with overlapped memory buffers;
  5090.         bcopy: copy memory, UNIX, works with overlapped memory buffers;
  5091.  
  5092.     LIBRARY
  5093.         TBA
  5094.  
  5095.     SYNTAX
  5096.         #include <TBA.h>
  5097.         void *ptr = memcpy(d, s, bytes);
  5098.         void *ptr = memmove(d, s, bytes);
  5099.         void *ptr = movmem(s, d, bytes);
  5100.         void *ptr = bcopy(s, d, bytes);
  5101.         void *d;
  5102.         void *s;
  5103.         size_t bytes;
  5104.  
  5105.     DESCRIPTION
  5106.         These functions copy memory from one region to another.  Unlike string
  5107.         routines these functions do not stop the copy when a NULL is
  5108.         encountered.
  5109.  
  5110.         || WARNING! Be careful about argument ordering.  Some calls  take the
  5111.         || source buffer first and other calls take the destination buffer
  5112.         || first.
  5113.  
  5114.         The ANSI committee really screwed up its standard, going for a
  5115.         destination, source ordering rather than the more logical source,
  5116.         destination ordering. Thus, many programmers will use the non-
  5117.         standard movmem call instead of the ANSI memmove call.  The ANSI
  5118.         function 'memcpy' as defined by the ANSI standard cannot handle
  5119.         overlapped memory areas.  The Amiga implementation can but you should
  5120.         remember this if you intend to port your code.
  5121.  
  5122.         :: NOTE: DICE's memory move optimizes the copy using movem when
  5123.         :: possible, yielding very fast memory copies for large buffers. The
  5124.         :: UNIX bcopy call exists for compatibility purposes and should not be
  5125.         :: used with new programs.
  5126.  
  5127.     INPUTS
  5128.         void *s;     source buffer
  5129.  
  5130.         void *d;     destination buffer
  5131.  
  5132.     RESULTS
  5133.         void *ptr;     pointer to the destination buffer(d)
  5134.  
  5135.     SEE ALSO
  5136.         memset, setmem, bzero, clrmem, cmpmem, memcmp
  5137.  
  5138.     EXAMPLE
  5139.         /*
  5140.          * This example copies the entire buffer, not just
  5141.          * the part containing the string.  Normally one just
  5142.          * uses string routines.
  5143.          */
  5144.         #include <string.h>
  5145.         #include <assert.h>
  5146.         
  5147.         main()
  5148.         {
  5149.            char s[16];
  5150.            char d[16];
  5151.            void *p;
  5152.            strcpy(s, "This is a test");
  5153.            p = movmem(s, d, sizeof(s));
  5154.            assert(p == d);
  5155.            puts(d);
  5156.            strcpy(s, "FuBarBletch");
  5157.            p = bcopy(s, d, sizeof(s));
  5158.            assert(p == d);
  5159.            puts(d);
  5160.            strcpy(s, "EchoBeko");
  5161.            p = memcpy(d, s, sizeof(s));
  5162.            assert(p == d);
  5163.            puts(d);
  5164.            strcpy(s, "GakFuBar");
  5165.            p = memmove(d, s, sizeof(s));
  5166.            assert(p == d);
  5167.            puts(d);
  5168.            return(0);
  5169.         }
  5170.  
  5171. dice/memset,setmem,clrmem,bzero              dice/memset,setmem,clrmem,bzero
  5172.  
  5173.     FUNCTION
  5174.         memset: ANSI, set memory buffer to a byte value
  5175.         setmem: DEFACTO, set memory buffer to a byte value
  5176.         clrmem: DICE,  zero out a memory buffer
  5177.         bzero: UNIX, zero out a memory buffer
  5178.  
  5179.     LIBRARY
  5180.         TBA
  5181.  
  5182.     SYNTAX
  5183.         #include <TBA.h>
  5184.         void *ptr = memset(buf, c, n);
  5185.         void *ptr = setmem(buf, n, c);
  5186.         void *ptr = clrmem(buf, n);
  5187.         void *ptr = bzero(buf, n);
  5188.         void *buf;
  5189.         int c;
  5190.         size_t n;
  5191.  
  5192.     DESCRIPTION
  5193.         These functions fill a memory buffer with the specified character c. 
  5194.         C is converted to an unsigned chararacter by the fill routine before
  5195.         beginning the fill.  N bytes are filled.
  5196.  
  5197.         || WARNING!  Again, watch out for argument ordering, especially for
  5198.         || the ANSI memset call.
  5199.  
  5200.         The ANSI committee really screwed up the call ordering so there is
  5201.         another defacto standard call called setmem. The function bzero exists
  5202.         for UNIX compatibility, and clrmem is yet another call (this time
  5203.         introduced by DICE--sorry!). memset and setmem are the most portable
  5204.         calls.
  5205.  
  5206.     INPUTS
  5207.         void *buf;     pointer to buffer to fill
  5208.  
  5209.         int  c;       character to copy into buffer
  5210.  
  5211.         (setmem, memset) size_t n;      # of bytes to fill
  5212.  
  5213.     RESULTS
  5214.         void *ptr;     pointer to buffer (== buf).
  5215.  
  5216.     SEE ALSO
  5217.         malloc, calloc, strdup, movmem, cmpmem
  5218.  
  5219.     EXAMPLE
  5220.         #include <string.h>
  5221.         #include <assert.h>
  5222.         #include <stdlib.h> 
  5223.         main()
  5224.         {
  5225.            char buf[32];
  5226.            char *b;
  5227.            b = setmem(buf, 32, 0);
  5228.            assert(b == buf);
  5229.            b = setmem(buf, 4, 'a');
  5230.            b = memset(buf + 4, 'b' , 4);
  5231.            puts(buf);      /*  aaaabbbb    */
  5232.            return(0);
  5233.         }
  5234.  
  5235. dice/mkdir                                                        dice/mkdir
  5236.  
  5237.     FUNCTION
  5238.         create a directory
  5239.  
  5240.     LIBRARY
  5241.         TBA
  5242.  
  5243.     SYNTAX
  5244.         #include <TBA.h>
  5245.         int error = mkdir(dirname)
  5246.         char *dirname;
  5247.  
  5248.     DESCRIPTION
  5249.         mkdir creates a new directory.  It returns 0 if successful, -1 if not
  5250.         (with errno set to an error code).
  5251.  
  5252.     INPUTS
  5253.         char *dirname;      filename of directory to create
  5254.  
  5255.     RESULTS
  5256.         int r;       0 if no error, < 0 if error
  5257.  
  5258.     SEE ALSO
  5259.         close, creat, fcntl, fdtofh, getfh, ioctl, isatty, lseek, mkdir, open,
  5260.         read, rmdir, unlink, write
  5261.  
  5262.     EXAMPLE
  5263.         main()
  5264.         {
  5265.            int r;
  5266.            r = mkdir("T:tmpdir");
  5267.            if (r == 0)
  5268.               puts("Created T:tmpdir successfully");
  5269.            else
  5270.               puts("Unable to create directory T:tmpdir");
  5271.         }
  5272.  
  5273. dice/_mods                                                        dice/_mods
  5274.  
  5275.     FUNCTION
  5276.         signed long modulus 32
  5277.  
  5278.     LIBRARY
  5279.         TBA
  5280.  
  5281.     SYNTAX
  5282.         TBA
  5283.  
  5284.     DESCRIPTION
  5285.         _mods is an assembly function that DICE uses whenever it needs to do a
  5286.         long modulus.  _mods is not callable from C.
  5287.  
  5288.     INPUTS
  5289.         D0  = 32 bit signed integer
  5290.  
  5291.         D1 = 32 bit signed integer
  5292.  
  5293.     RESULTS
  5294.         D0 = D0 * D1
  5295.  
  5296.     SEE ALSO
  5297.         _divs, _divu, _modu, _muls, _mulu
  5298.  
  5299.     EXAMPLE
  5300.         TBA
  5301.  
  5302. dice/_modu                                                        dice/_modu
  5303.  
  5304.     FUNCTION
  5305.         unsigned long modulus 32
  5306.  
  5307.     LIBRARY
  5308.         TBA
  5309.  
  5310.      SYNTAX
  5311.         TBA
  5312.  
  5313.     DESCRIPTION
  5314.         _modu is an assembly function that DICE uses whenever it needs to do
  5315.         an unsigned long modulus.  _modu is not callable from C.
  5316.  
  5317.     INPUTS
  5318.         D0  = 32 bit signed integer
  5319.  
  5320.         D1 = 32 bit signed integer
  5321.  
  5322.     RESULTS
  5323.         D0 = D0 * D1
  5324.  
  5325.     SEE ALSO
  5326.         _divs, _divu, _mods, _muls, _mulu
  5327.  
  5328.     EXAMPLE
  5329.         TBA
  5330.  
  5331. dice/_muls                                                        dice/_muls
  5332.  
  5333.     FUNCTION
  5334.         signed long multiply 32*32
  5335.  
  5336.     LIBRARY
  5337.         TBA
  5338.  
  5339.      SYNTAX
  5340.         TBA
  5341.  
  5342.     DESCRIPTION
  5343.         _muls is an assembly function that DICE uses whenever it needs to do
  5344.         long multiplication.  _muls is not callable from C.
  5345.  
  5346.     INPUTS
  5347.         D0 = 32 bit signed integer
  5348.  
  5349.         D1 = 32 bit signed integer
  5350.  
  5351.     RESULTS
  5352.         D0 = D0 * D1
  5353.  
  5354.     SEE ALSO
  5355.         _divs, _divu, _mods, _modu, _mulu
  5356.  
  5357.     EXAMPLE
  5358.         TBA
  5359.  
  5360. dice/_mulu                                                        dice/_mulu
  5361.  
  5362.     FUNCTION
  5363.         unsigned long multiply 32/32->32
  5364.  
  5365.     LIBRARY
  5366.         TBA
  5367.  
  5368.      SYNTAX
  5369.         TBA
  5370.  
  5371.     DESCRIPTION
  5372.         _mulu is an assembly function that DICE uses whenever it needs to do
  5373.         unsigned long multiplication.  _mulu is not callable from C.
  5374.  
  5375.     INPUTS
  5376.         TBA
  5377.  
  5378.     RESULTS
  5379.         TBA
  5380.  
  5381.     SEE ALSO
  5382.         _divs, _divu, _mods, _modu, _muls
  5383.  
  5384.     EXAMPLE
  5385.         TBA
  5386.  
  5387. dice/onbreak                                                    dice/onbreak
  5388.  
  5389.     FUNCTION
  5390.         Set special ^C handler (not ANSI)
  5391.  
  5392.     LIBRARY
  5393.         TBA
  5394.  
  5395.     SYNTAX
  5396.         #include <TBA.h>
  5397.         typedef int (*fptr)();
  5398.         fptr oldfunc = onbreak(newfunc);
  5399.         fptr newfunc;
  5400.  
  5401.     DESCRIPTION
  5402.         onbreak sets a special function to handle ^C.  It takes a pointer to
  5403.         this function and returns a pointer to the previous onbreak function,
  5404.         if any.  When ^C is hit, the special onbreak function is called before
  5405.         any other action. If the onbreak function returns a non-zero value, ^C
  5406.         aborts the program like it usually does.  If the function returns 0,
  5407.         however, the ^C is completely ignored.
  5408.  
  5409.     INPUTS
  5410.         TBA
  5411.  
  5412.     RESULTS
  5413.         TBA
  5414.  
  5415.     SEE ALSO
  5416.         atexit
  5417.  
  5418.     EXAMPLE
  5419.         /*
  5420.         * Note: The reentrancy check is needed because of both
  5421.         * the puts and the sleep() all.
  5422.         */
  5423.         #include <stdio.h>
  5424.         #include <stdlib.h>
  5425.         
  5426.         int brk()
  5427.         {
  5428.            static short cnt = 0; /*  check for reentrancy */
  5429.            if (cnt)              /*  if not 0 then reentered! */
  5430.               return(0);
  5431.               ++cnt;
  5432.            puts("Nah Nah, you can't break me!");
  5433.            sleep(1);
  5434.            --cnt;
  5435.            return(0);
  5436.         }
  5437.         
  5438.         int main()
  5439.         {
  5440.            short i;
  5441.            onbreak(brk);
  5442.            puts("Hit ^C while I loop from 1 to 100, as many times
  5443.            as you want");
  5444.            sleep(2);
  5445.            for (i = 1; i <= 100; ++i)
  5446.            printf("Loop, counting, count = %d\n", i);
  5447.            return(0);
  5448.            =
  5449.         }
  5450.  
  5451. dice/open                                                          dice/open
  5452.  
  5453.     FUNCTION
  5454.         open a file
  5455.  
  5456.     LIBRARY
  5457.         TBA
  5458.  
  5459.     SYNTAX
  5460.         #include <fcntl.h>
  5461.         int fd = open(name, modes);
  5462.         char *name;
  5463.         int modes;
  5464.  
  5465.     DESCRIPTION
  5466.         open opens a file of the specified name using the specified modes. 
  5467.         The combinations yield different results as described below:
  5468.  
  5469.              O_RDONLY open file for reading only
  5470.             O_WRONLY open file for writing only
  5471.             O_RDWR open file for reading and writing
  5472.             O_NDELAY open file non-blocking (not implemented)
  5473.             O_APPEND open file for writing only and force all writes to append to
  5474.         the file regardless of the current seek position.
  5475.  
  5476.         O_CREAT creates the file if it does not exist; O_TRUNC truncates the
  5477.         file if it does exist; O_EXCL is used only with O_CREAT and if the
  5478.         file already exists the open will fail; O_BINARY opens the file for
  5479.         binary reading and writing, vs text.  This flag is ignored by DICE
  5480.         since there is no difference on the Amiga.  However, on IBM systems
  5481.         CR-LF must be converted to an LF when reading text files. open returns
  5482.         a descriptor (>= 0) or error (< 0) on failure.
  5483.  
  5484.         :: NOTE: Refer to the file_descriptor manual page for general
  5485.         :: information. Unlike file pointers and file handles, the file
  5486.         :: descriptor is checked for validity and will simply return an error
  5487.         :: if illegal.
  5488.  
  5489.     INPUTS
  5490.         char *name;      filename to open
  5491.  
  5492.         long modes;     modes to open the file with
  5493.  
  5494.     RESULTS
  5495.         int fd;     A file descriptor if >= 0, an error if < 0.
  5496.  
  5497.     SEE ALSO
  5498.         close, creat, fcntl, fdtofh, ioctl, isatty, lseek, mkdir, read, rmdir,
  5499.         unlink, write
  5500.  
  5501.     EXAMPLE
  5502.         #include <fcntl.h>
  5503.         #include <assert.h> 
  5504.         main()
  5505.         {
  5506.            int fd;
  5507.            fd = open("T:xx", O_WRONLY|O_CREAT|O_TRUNC);
  5508.            assert(fd >= 0);
  5509.            close(fd);
  5510.            fd = open("T:xx", O_CREAT|O_EXCL|O_TRUNC|O_WRONLY);
  5511.            assert(fd < 0); /*  should fail, file already exists */
  5512.            remove("T:xx");
  5513.            fd = open("T:xx", O_CREAT|O_TRUNC|O_WRONLY);
  5514.            assert(fd >= 0);    /*  should work     */
  5515.            write(fd, "FuBar\n", 6);
  5516.            close(fd);
  5517.            fd = open("T:xx", O_APPEND|O_WRONLY);
  5518.            assert(fd >= 0);
  5519.            write(fd, "BxBar\n", 6);
  5520.            close(fd);
  5521.            return(0);
  5522.         }
  5523.         
  5524.         1> sampleprg 1> type t:xx FuBar BxBar
  5525.         1>
  5526.  
  5527. dice/perror                                                      dice/perror
  5528.  
  5529.     FUNCTION
  5530.         output error message associated with errno and text to stderr.
  5531.  
  5532.     LIBRARY
  5533.         TBA
  5534.  
  5535.     SYNTAX
  5536.         #include <stdio.h>
  5537.         void perror(str);
  5538.         const char *str;
  5539.  
  5540.     DESCRIPTION
  5541.         perror outputs the specified string, a colon, and the error number and
  5542.         error message associated with the current value of errno to stderr,
  5543.         ending with a newline.  Using perror is a common way to generate error
  5544.         messages due to IO failures.
  5545.  
  5546.     INPUTS
  5547.         char *str;     string message to include in error output
  5548.  
  5549.     RESULTS
  5550.         none
  5551.  
  5552.     SEE ALSO
  5553.         TBA
  5554.  
  5555.     EXAMPLE
  5556.         #include <stdio.h>
  5557.         main()
  5558.         {
  5559.            FILE *fp = fopen("T:DoesNotExist", "r");
  5560.            if (fp)
  5561.            {
  5562.               puts("T:DoesNotExist isn't supposed to exist!"); exit(1);
  5563.            }
  5564.            perror("fopen");
  5565.            return(0);
  5566.         }
  5567.  
  5568. dice/pow,fpow                                                  dice/pow,fpow
  5569.  
  5570.     FUNCTION
  5571.         pow: return one double to the power of another
  5572.  
  5573.         fpow: return one float to the power of another
  5574.  
  5575.     LIBRARY
  5576.         TBA
  5577.  
  5578.     SYNTAX
  5579.         #include <math.h>
  5580.         double a = pow(b, bp);
  5581.         double bp;
  5582.         double b;
  5583.         float  c = flog(d, dp);
  5584.         float  dp; float  d;
  5585.  
  5586.     DESCRIPTION
  5587.         pow returns one double to the power of another; fpow returns one float
  5588.         to the power of another.
  5589.  
  5590.      INPUTS
  5591.         double b;     double floating point value (base)
  5592.  
  5593.         double bp;     double floating point value (exponent)
  5594.  
  5595.         float d;       float floating point value (base)
  5596.  
  5597.         float dp;     float floating point value (exponent)
  5598.  
  5599.     RESULTS
  5600.         double a;     double floating point value
  5601.  
  5602.         float c;     float floating point value
  5603.  
  5604.     SEE ALSO
  5605.         acos, asin, atan, cos, exp, fabs, log, log10, pow, sin, sqrt, tan
  5606.         facos, fasin, ...
  5607.  
  5608.     EXAMPLE
  5609.         /*
  5610.          *  compile with the math library -lm 
  5611.          */
  5612.         #include <math.h>
  5613.         #include <stdio.h>
  5614.         main()
  5615.         {
  5616.            {
  5617.               double a = pow(0.25, 4.0); 
  5618.               printf("pow 0.25 ^^ 4.0 = %lf\n", a);
  5619.               /*  0.0039 */   
  5620.            } 
  5621.            {
  5622.               /*  less accuracy  */
  5623.               float a = fpow(0.25, 4.0);
  5624.               printf("pow 0.25 ^^ 4.0 = %lf\n", (double)a); 
  5625.            } 
  5626.            return(0);
  5627.         }
  5628.  
  5629.         `@MAJOR HEADING = printf, fprintf, sprintf, vprintf, vfprintf,
  5630.         vsprintf
  5631.  
  5632.     FUNCTION
  5633.         formatted output to stdout, file pointer, or buffer
  5634.  
  5635.     LIBRARY
  5636.         TBA
  5637.  
  5638.     SYNTAX
  5639.         #include <stdio.h>
  5640.         #include <stdarg.h> 
  5641.         /*  v[f/s]printf() only */
  5642.         int n = printf(fmt, ...);
  5643.         int n = fprintf(fp, fmt, ...);
  5644.         int n = sprintf(buf, fmt, ...);
  5645.         int n = vprintf(fmt, argvect);
  5646.         int n = vfprintf(fp, fmt, argvect);
  5647.         int n = vsprintf(buf, fmt, argvect);
  5648.         FILE *fp;
  5649.         char *fmt;
  5650.         char *buf;
  5651.         va_list argvect;
  5652.  
  5653.     DESCRIPTION
  5654.         These various connotations offer formatted printing.  printf and
  5655.         vprintf output to stdout; fprintf and vfprintf output to a file
  5656.         pointer (fp); sprintf and vsprintf output to a character buffer.  All
  5657.         routines return the number of characters written if successful, a
  5658.         negative number if not.  Only sprintf and vsprintf are limited in
  5659.         terms of output size (it cannot exceed the buffer you give it). The
  5660.         common argument to all routines is the format specifier.  The format
  5661.         specifier is scanned to determine how to handle the arguments to the
  5662.         call (or the arglist for v*printf connotations). Characters are copied
  5663.         to the output until a % is encountered. %% indicates a literal '%'
  5664.         character.  Otherwise, the % is followed by a control sequence that
  5665.         tells printf how to output an argument quantity.  The quantity is
  5666.          output and the scan continues until the end of the format string.
  5667.         The % format is as follows:
  5668.  
  5669.         %[flags][#[.#]][modifier]<conversion-specifier>
  5670.         Items in brackets are option.  After the % zero or more flags may be
  5671.         specified.  Then, an optional integer which represents the minimum
  5672.         field width for the object may also be specified.  If an integer is
  5673.         specified it may be followed by a period and another integer that
  5674.         represents that precision with which a number is printed. Zero or more
  5675.         modifiers may then be specified followed by a mandatory conversion
  5676.         specifier.
  5677.  
  5678.         Either or both integers (#[.#]) may be specified as a '*', as in
  5679.         "%*d", specifying that the minimum field width and/or precision is
  5680.         specified as an integer in the argument that occurs before the
  5681.         conversion object.  For example, printf("x%*dx\n", 10, 23); would
  5682.         print the number 23 right justified in a field 10 characters wide.
  5683.  
  5684.         FLAGS:
  5685.  
  5686.             -     left justify text within its field, otherwise output is right
  5687.          justified
  5688.             +     precede a signed number with a plus sign if it is positive
  5689.          (negative
  5690.                 numbers are always preceded with a minus sign).
  5691.             <space>    precede a positive signed number with a space so the
  5692.          number's
  5693.                 width matches that of itself if it were negative.
  5694.             #    force numeric data items to be formatted such that their type is
  5695.          known.
  5696.         The following effects occur given a conversion specifier:
  5697.             e, E, f, F    always retains decimal point
  5698.             g, G    always retains decimal point 
  5699.                 and trailing zeros are kept
  5700.             x, X    prints '0x' and '0X' respectively before the number
  5701.                 (currently not implemented by DICE)     0    pad with zeros instead of
  5702.          spaces.  Ignored if a precision is specified
  5703.                 or if the '-' flag is specified.
  5704.                 (currently partially implemented by DICE) MODIFIERS
  5705.             h     indicates the corresponding integer argument is a short or an
  5706.          unsigned short.
  5707.                  Under DICE, this has no effect since integers are 32 bits
  5708.             l    Indicates the corresponding integer argument is a long or unsigned
  5709.         long.             Indicates floating point argument is a double (else is a
  5710.         float) under DICE,             for integers, this is superfluous, but for
  5711.         portability reasons you want to             specify it when an argument is
  5712.          explicitly a long.
  5713.             L    indicates the corresponding floating point argument is a long
  5714.         double (16 byte quantity)  (currently not implemented by DICE)
  5715.         CONVERSION SPECIFIER     c     Output the character represented by the
  5716.          integer quantity|
  5717.              d    Output a signed integer
  5718.             e    Output a double quantity in exponential form, the format: The
  5719.         precision             specifies the number of digits beyond the decimal point
  5720.          to print
  5721.                  [-]d.dddddde+/-dd
  5722.              E    e conversion but use upper case E in exponent: E+/-dd
  5723.             f    Output a double quantity in the form:  The precision specifies the
  5724.          number             of digits beyond the decimal point to print [-]d.dddddd\
  5725.             g    Output a double quantity using either the 'e' or 'f' form,
  5726.          depending on the             exponent.
  5727.             G    Output a double quantity using either the 'E' or 'f' form,
  5728.          depending on the             exponent.
  5729.              i    same as 'd'
  5730.             n    The argument is a pointer to an integer which is used to set the
  5731.         integer to             the bytes written out so far. This is especially useful
  5732.         with sprintf to             determine where a particular part of the format
  5733.          begins in the output buffer.
  5734.              o    The unsigned integer quantity is converted to ASCII-octal
  5735.              p    The pointer is printed (basically the address is printed)
  5736.              s    The string represented by the character pointer is printed
  5737.              u    The unsigned integer quantity is converted to ASCII-decimal
  5738.             x    The unsigned integer quantity is converted to ASCII-hex using
  5739.         '0'-'9', 'a'-'f'.     X    The unsigned integer quantity is converted to
  5740.          ASCII-hex using upper case
  5741.                  A-F instead of lower case.
  5742.  
  5743.     INPUTS
  5744.         FILE *fp;     file pointer (fprintf, vfprintf)
  5745.  
  5746.         char *fmt;     format string, e.g. "Answer is %d\n"
  5747.  
  5748.         char *buf;      buffer (sprintf, vsprintf)
  5749.  
  5750.         va_list argvect;     arg list (vprintf, vfprintf, vsprintf)
  5751.  
  5752.     RESULTS
  5753.         int n;      number of characters written if successful, a negative
  5754.  
  5755.             number if not.  For sprintf and vsprintf the NULL character at the
  5756.         end
  5757.  
  5758.              of the string is NOT included in the count.
  5759.  
  5760.     SEE ALSO
  5761.         puts, fputs, fwrite
  5762.  
  5763.     EXAMPLE
  5764.         /*
  5765.          *  Example use of most conversion specifiers.  Compile 
  5766.          *  -lm to get the math pfmt.
  5767.          */
  5768.         #include <stdio.h>
  5769.         #include <stdarg.h>
  5770.         void gagprint();
  5771.         main()
  5772.         {
  5773.            char buf[256];
  5774.            int i;
  5775.            int n;
  5776.            `n = printf("ab%c %03d %le %lf %2.2lf %n%o %p %sXX %u %x
  5777.                       %X %08lx\n", 'c',             /*  %c      -> 'c'    */
  5778.         43,                                   /*  %03d    -> '043'    */
  5779.      
  5780.                  1.23E-2, 1.23E-2, 1.257, /*  %2.2lf  -> 1.26 */ &i, 
  5781.         11,                                   /*  %o      -> '13'     */ 
  5782.     
  5783.         buf,                                  /*  %p     -> <hex-ptr- addr>  
  5784.          */
  5785.                       "FuBar", 32094,              /*  %u      -> 32094  */
  5786.                       4095,                               /*  %x   */ 
  5787.                       4095,                               /*  %X  */ 
  5788.                       4095                                /* %08lx    */  );
  5789.            printf("%d chars written\n", n);
  5790.            n = printf("%*s%s\n", i, "", "^Octal Number");
  5791.            printf("%d chars written\n", n);
  5792.            n = sprintf(buf, "FuBar%s", "Bletch");
  5793.            puts(buf); 
  5794.            printf("%d chars written\n", n);
  5795.            n = fprintf(stdout, "This is an fprintf\n");
  5796.            printf("%d chars written\n", n);
  5797.            gagprint("%d %d %d\n", 1, 2, 3);
  5798.            return(0);
  5799.         }
  5800.         void gagprint(ctl, ...)
  5801.         char *ctl;
  5802.         {
  5803.            va_list va;
  5804.            int n;
  5805.            va_start(va, ctl);
  5806.            n = vprintf(ctl, va);
  5807.            printf("%d chars written\n", n);
  5808.            va_end(va);
  5809.         }
  5810.  
  5811. dice/putchar                                                    dice/putchar
  5812.  
  5813.     FUNCTION
  5814.         output character to stdout (MACRO)
  5815.  
  5816.     LIBRARY
  5817.         TBA
  5818.  
  5819.     SYNTAX
  5820.         #include <stdio.h>
  5821.         int r = putchar(c);
  5822.  
  5823.     DESCRIPTION
  5824.         putchar outputs a character to stdout, returning the output character
  5825.         unless an error occured.  If an error occured then EOF is returned.
  5826.  
  5827.         :: NOTE: Refer to the file_pointer manual page for general
  5828.         :: information.
  5829.  
  5830.     INPUTS
  5831.         int c;     character to output, 0 to 255
  5832.  
  5833.     RESULTS
  5834.         int r;       same as c unless error occured in which case EOF.
  5835.  
  5836.     SEE ALSO
  5837.         putc, fputc, fread, fwrite, getc, getchar
  5838.  
  5839.     EXAMPLE
  5840.         /*
  5841.          * copy stdin to stdout using getchar/putchar. Normally one
  5842.          * uses fread/fwrite, but I'll save that for the fread manual
  5843.          * page.  Note that I output the initial message to stderr so it
  5844.          * does not get stuck into stdout in case the user has
  5845.          * redirected stdout.
  5846.          * 
  5847.          * See getc manual page for equivalent example using 
  5848.          * getc/putc 
  5849.          */
  5850.         #include <stdio.h>
  5851.         main()
  5852.         {   
  5853.              int c;
  5854.              fputs("Type a couple of lines, then ^\ (EOF)\n", stderr);
  5855.              while ((c = getchar()) != EOF)
  5856.              {
  5857.                 putchar(c);
  5858.              }
  5859.              return(0);
  5860.         }
  5861.  
  5862. dice/qsort                                                        dice/qsort
  5863.  
  5864.     FUNCTION
  5865.         sort an array of objects
  5866.  
  5867.     LIBRARY
  5868.         TBA
  5869.  
  5870.     SYNTAX
  5871.         #include <stdio.h>
  5872.         #include <stdlib.h>
  5873.         (void) qsort(array, numElem, elemSize, compare_func)
  5874.         void *array;
  5875.         size_t numElem;
  5876.         size_t elemSize;
  5877.         int (*compare_func)(const void *arg1, const void *arg2);
  5878.  
  5879.     DESCRIPTION
  5880.         qsort sorts numElem elements in an array based at array. Each element
  5881.         is elemSize bytes long. When a comparison is required, qsort calls the
  5882.         passed compare_func function pointer with a pointer to the two
  5883.         elements being sorted. DICE currently implements qsort with a simple
  5884.         merge sort algorithm, using relatively slow movmems to avoid having to
  5885.         allocate much additional storage. Very little stack is used. 
  5886.         Traditional qsort employs a stack based quick-sort algorithm that
  5887.         might use a massive amount of stack.
  5888.  
  5889.     INPUTS
  5890.         void *array;     pointer to base of array of objects
  5891.  
  5892.         size_t numElem;     number of elements in the array
  5893.  
  5894.         size_t elemSize;      size, in bytes, of each element
  5895.  
  5896.         int (*compare_func)()     function pointer to compare function given
  5897.  
  5898.             pointers to two of the elements
  5899.  
  5900.     RESULTS
  5901.         none
  5902.  
  5903.     SEE ALSO
  5904.         TBA
  5905.  
  5906.     EXAMPLE
  5907.         #include <stdio.h>
  5908.         #include <stdlib.h>
  5909.         char *StrList[6] = 
  5910.         {   
  5911.            "fubar", "able", "yum", "quack",
  5912.            "rigger", "battle" 
  5913.         };
  5914.         my_comp(s1, s2)
  5915.         char **s1; char **s2;
  5916.         {
  5917.            return(strcmp(*s1, *s2));
  5918.         }
  5919.         main()
  5920.         {
  5921.            short i;
  5922.            qsort(StrList, 6, sizeof(char *), my_comp);
  5923.            for (i = 0; i < 6; ++i)
  5924.            printf("%d %s\n", i, StrList[i]);
  5925.            return(0);
  5926.         }
  5927.  
  5928. dice/raise                                                        dice/raise
  5929.  
  5930.     FUNCTION
  5931.         raise a signal (cause an 'interrupt' synchronously)
  5932.  
  5933.     LIBRARY
  5934.         TBA
  5935.  
  5936.     SYNTAX
  5937.         #include <TBA.h>
  5938.         int r = raise(signo);
  5939.         int signo;
  5940.  
  5941.     DESCRIPTION
  5942.         raise causes a signal to occur and the appropriate action to be taken.
  5943.         It returns 0 on success, -1 if the signo is invalid (outside the range
  5944.         of allowed signals).  When you raise a signal, the signal is set back
  5945.         to its default vector before the handler is called.  Thus, if you are
  5946.         allowing multiple signals to occur you MUST restore the signal vector
  5947.         with signal from your signal handler before it returns.
  5948.  
  5949.     INPUTS
  5950.         int signo;    signal to cause
  5951.  
  5952.     RESULTS
  5953.         int r;       0 on success, -1 if signo is out of range.
  5954.  
  5955.     SEE ALSO
  5956.         signal
  5957.  
  5958.     EXAMPLE
  5959.         /*
  5960.          *  prints the numbers 0 to 99, except only gets to 50 because
  5961.          *  we 'cause' a ^C.  */
  5962.         #include <signal.h>
  5963.         main()
  5964.         {
  5965.            short i;
  5966.            for (i = 0; i < 100; ++i)
  5967.            {
  5968.               printf("i = %d\n", i); if (i == 50)
  5969.               raise(SIGINT);
  5970.            }
  5971.               return(0);
  5972.         }
  5973.  
  5974. dice/rand                                                          dice/rand
  5975.  
  5976.     FUNCTION
  5977.         return pseudo-random number
  5978.  
  5979.     LIBRARY
  5980.         TBA
  5981.  
  5982.     SYNTAX
  5983.         #include <stdio.h>
  5984.         #include <stdlib.h>
  5985.         int n = rand(void);
  5986.         (void) srand(seed)
  5987.         unsigned int seed;
  5988.  
  5989.     DESCRIPTION
  5990.         rand returns a random number as a positive integer ranging from 0 to
  5991.         RAND_MAX.  RAND_MAX is defined in stdlib.h and is at least 32767. 
  5992.          DICE implements it as 2147483647 == 0x7FFFFFFF.
  5993.         The initial seed used to generate the pseudo-random sequence is 1, but
  5994.         may be reinitialized to any number you desire using srand. rand is
  5995.         guaranteed to return the same sequence for the same seed.
  5996.  
  5997.     INPUTS
  5998.         none
  5999.  
  6000.     RESULTS
  6001.         int n;      returned by rand(), this number will be a positive integer.
  6002.  
  6003.     SEE ALSO
  6004.         TBA
  6005.  
  6006.     EXAMPLE
  6007.         #include <stdio.h>
  6008.         #include <stdlib.h>
  6009.         
  6010.         main(ac, av)
  6011.         char*av[];
  6012.         {
  6013.            short i;
  6014.            short j;
  6015.            if (ac == 2)
  6016.            {
  6017.               int seed =
  6018.               strtol(av[1], NULL, 0);
  6019.               srand(seed);
  6020.               printf("using seed = %d\n",
  6021.               seed);
  6022.            }
  6023.            else
  6024.            {
  6025.               puts("using seed = 1");
  6026.            }
  6027.            for (i = 0; i    < 10; ++i)
  6028.            {
  6029.               int n = rand();
  6030.               printf("Random number: %08lx
  6031.               (%d)\n", n, n);
  6032.            }
  6033.            for (i = 0; i < 31; ++i)
  6034.            {
  6035.               int isone = 0;
  6036.               long mask = 1 << i;
  6037.               for (j = 0; j < 32767; ++j)
  6038.               {
  6039.                  if (rand() & mask) ++isone;
  6040.               }
  6041.               printf("bit %d %5d:%-5d (dev %d)\n", i,
  6042.               32767 - isone, isone, 16384 -isone);
  6043.            } 
  6044.            return(0);
  6045.         }
  6046.  
  6047. dice/read                                                          dice/read
  6048.  
  6049.     FUNCTION
  6050.         read data from a file
  6051.  
  6052.     LIBRARY
  6053.         TBA
  6054.  
  6055.     SYNTAX
  6056.         #include <TBA.h>
  6057.         int r = read(fd, buf, bytes);
  6058.         int fd;
  6059.         void *buf;
  6060.         int bytes;
  6061.  
  6062.     DESCRIPTION
  6063.         read reads data from a file starting at the current seek position. 
  6064.         read returns the number of bytes read or -1 if a read error occurs.
  6065.         With normal files, read will always return the number of bytes
  6066.         requested until the end of file is reached, in which case read may
  6067.         return fewer than the number of bytes requested.  If at the end of a
  6068.         file, read will return 0. With devices read may or may not return the
  6069.         number of bytes requested depending on the device.
  6070.  
  6071.         :: NOTE: Refer to the file_descriptor manual page for general
  6072.         :: information Unlike file pointers and file handles, the file
  6073.         :: descriptor is checked for validity and will simply return an error
  6074.         :: if illegal.
  6075.  
  6076.     INPUTS
  6077.         int fd;     file descriptor to read from
  6078.  
  6079.         void *buf;     pointer to buffer to read data into
  6080.  
  6081.         int len;     maximum number of bytes to read
  6082.  
  6083.     RESULTS
  6084.         int r;       number of bytes actually read (could be less than len or 0),
  6085.         @RESULTS =     or < 0 if error.
  6086.  
  6087.     SEE ALSO
  6088.         close, creat, fcntl, fdtofh, ioctl, isatty, lseek, mkdir, open, read,
  6089.         rmdir, unlink, write
  6090.  
  6091.     EXAMPLE
  6092.         #include <fcntl.h>
  6093.         #include <assert.h>
  6094.         
  6095.         main()
  6096.         {
  6097.            int fd;
  6098.            int r;
  6099.            char buf[32];
  6100.            fd = open("T:xx", O_WRONLY|O_CREAT|O_TRUNC);
  6101.            assert(fd >= 0);
  6102.            write(fd, "FuBar\n", 6);
  6103.            close(fd);
  6104.            fd = open("T:xx", O_RDONLY);
  6105.            assert(fd >= 0);
  6106.            r = read(fd, buf, sizeof(buf));  /* sizeof(buf) == 32 */
  6107.            close(fd);
  6108.            assert(r == 6);
  6109.            /*
  6110.             *  note that the buffer is not terminated with a NULL,
  6111.             *  but since we are using write() which requires a
  6112.             *  length it does not matter
  6113.             */
  6114.            write(1, buf, r);
  6115.         }
  6116.  
  6117. dice/realloc                                                    dice/realloc
  6118.  
  6119.     FUNCTION
  6120.         reallocate memory allocated by calloc, malloc, or strdup
  6121.  
  6122.     LIBRARY
  6123.         TBA
  6124.  
  6125.     SYNTAX
  6126.         #include <TBA.h>
  6127.         void *newptr = realloc(oldptr, bytes)
  6128.         void *oldptr;
  6129.         size_t bytes;
  6130.  
  6131.     DESCRIPTION
  6132.         realloc reallocates a previously allocated buffer, making it larger or
  6133.         smaller.  It returns a pointer to a new buffer which might be the same
  6134.         as the old buffer, but might not.  Data in the original buffer is
  6135.         copied to the new buffer and the original buffer is freed.  When
  6136.         extending a buffer with realloc note that the extended bytes (beyond
  6137.         the original buffer) will come up garbage.  You may pass a NULL as the
  6138.         first argument to realloc which basically makes realloc a malloc.
  6139.  
  6140.     INPUTS
  6141.         void *oldptr;    pointer to original allocated buffer
  6142.  
  6143.         size_t bytes;        size of new buffer
  6144.  
  6145.     RESULTS
  6146.         void *newptr;     pointer to new buffer
  6147.  
  6148.     SEE ALSO
  6149.         malloc, calloc, strdup
  6150.  
  6151.     EXAMPLE
  6152.         #include <string.h>
  6153.         #include <assert.h>
  6154.         #include <stdlib.h>
  6155.         main()
  6156.         {
  6157.            char *s;
  6158.            int len;
  6159.            s = strdup("This is a test");
  6160.            assert(s);
  6161.            len = strlen(s);
  6162.            /*
  6163.             *  Remember that len does not include the NULL byte at
  6164.             * the end of the string
  6165.             */
  6166.            s = realloc(s, len + 8);        /*  make more room */
  6167.            assert(s);
  6168.            /*
  6169.             *  we can use strcat since in extending the allocated
  6170.             *  string the NULL *was* copied along with the string
  6171.             *  during the realloc.
  6172.             */
  6173.            strcat(s, "xx");
  6174.            puts(s);        /*  This is a testxx    */
  6175.            return(0);
  6176.         }
  6177.  
  6178. dice/rega4                                                        dice/rega4
  6179.  
  6180.     FUNCTION
  6181.         return current contents of register A4
  6182.  
  6183.     LIBRARY
  6184.         TBA
  6185.  
  6186.     SYNTAX
  6187.         #include <TBA.h>
  6188.         char *basePtr = rega4();
  6189.  
  6190.     DESCRIPTION
  6191.         rega4 is not geta4;  rega4 simply returns the current contents of the
  6192.         A4 register when you need it.  Note that DICE offsets the A4 register
  6193.         32766 from the actual small-data base so as to be able to use the
  6194.         entire -32768 to 32767 range to access 64 kilobytes of small-data. 
  6195.         Note that a rega4 call inside a subroutine qualified with __geta4 is
  6196.         guaranteed to return the data base pointer.  Also, a rega4 call from
  6197.         any subroutine not called from an interrupt or a call back will return
  6198.         the proper data base pointer.
  6199.  
  6200.     SEE ALSO
  6201.         TBA
  6202.  
  6203.     EXAMPLE
  6204.         TBA
  6205.  
  6206. dice/remove                                                      dice/remove
  6207.  
  6208.     FUNCTION
  6209.         delete a file
  6210.  
  6211.     LIBRARY
  6212.         TBA
  6213.  
  6214.     SYNTAX
  6215.         #include <stdio.h>
  6216.         int error = remove(filename);
  6217.         const char *filename;
  6218.  
  6219.     DESCRIPTION
  6220.         remove deletes the specified file path returning 0 on success, a
  6221.         negative number on failure.  On the Amiga, an error will occur if you
  6222.         try to delete a file currently opened by yourself or any other
  6223.         process.  remove is an ANSI function.  unlink does the same thing but
  6224.         is a UNIX-compatible function.
  6225.  
  6226.     INPUTS
  6227.         char *filename;     filename to delete
  6228.  
  6229.     RESULTS
  6230.         int error;     0 on success, a negative number on failure
  6231.  
  6232.     SEE ALSO
  6233.         unlink
  6234.  
  6235.     EXAMPLE
  6236.         /*
  6237.         * delete the file 'T:xxx'
  6238.         */
  6239.         #include <stdio.h>
  6240.         main()
  6241.         {
  6242.            int error = remove("T:XXX");
  6243.            if (error < 0)
  6244.            {
  6245.               perror("remove(\"T:XXX\") failed"); 
  6246.               exit(1);
  6247.            }
  6248.            puts("T:XXX has been deleted");
  6249.            return(0);
  6250.         }
  6251.  
  6252. dice/rename                                                      dice/rename
  6253.  
  6254.     FUNCTION
  6255.         rename a file, or move a file from one directory to another on the
  6256.         same filesystem.
  6257.  
  6258.     LIBRARY
  6259.         TBA
  6260.  
  6261.     SYNTAX
  6262.         #include <stdio.h>
  6263.         int error = rename(origname, newname);
  6264.         const char *origname;
  6265.         const char *newname;
  6266.  
  6267.     DESCRIPTION
  6268.         rename renames a file.  You may also use rename to move a file (and
  6269.         rename at the same time) to another directory on the same filesystem. 
  6270.         rename returns 0 on success, a negative number on failure.
  6271.  
  6272.     INPUTS
  6273.         const char *origname;     existing file const char
  6274.  
  6275.         *newname;     new filename and/or path
  6276.  
  6277.     RESULTS
  6278.         int error;    0 on success, a negative number on failure
  6279.  
  6280.     SEE ALSO
  6281.         rewind
  6282.  
  6283.     EXAMPLE
  6284.         /*
  6285.          *  create the file T:xxjunk and the directory T:junkdir then
  6286.          *  move T:xxjunk into T:junkdir and rename to T:yyjunk at the 
  6287.          * same time.  *
  6288.          * As is aptly demonstrated by this example, some errors are not 
  6289.          * really errors.  For example, mkdir where the dir already exists
  6290.          * is not usually an error. 
  6291.          */
  6292.         #include <stdio.h>
  6293.         #include <assert.h> 
  6294.         #include <errno.h>
  6295.         main()
  6296.         {
  6297.            FILE *fp;    int error;
  6298.            error = mkdir("T:junkdir");
  6299.            if (error < 0 && errno != EEXISTS)
  6300.               perror("mkdir");
  6301.            fp = fopen("T:xxjunk", "w"); 
  6302.            if (fp == NULL)
  6303.            {
  6304.                 perror("fopen"); exit(1); 
  6305.            }
  6306.            fprintf(fp, "This file was originally
  6307.            T:xxjunk!\n");
  6308.             fclose(fp);
  6309.             /*
  6310.             * now rename  
  6311.             */
  6312.             error = rename("T:xxjunk", "T:junkdir/yyjunk");
  6313.             if (error < 0)
  6314.                perror("rename T:xxjunk to T:junkdir/yyjunk");
  6315.             else
  6316.                puts("rename succeeded, look in T:junkdir");
  6317.             return(0);
  6318.         }
  6319.  
  6320. dice/rewind                                                      dice/rewind
  6321.  
  6322.     FUNCTION
  6323.         seek filepointer to beginning of file
  6324.  
  6325.     LIBRARY
  6326.         TBA
  6327.  
  6328.     SYNTAX
  6329.         #include <stdio.h>
  6330.         void rewind(fp);
  6331.         FILE *fp;
  6332.  
  6333.     DESCRIPTION
  6334.         rewind rewinds the file to the beginning, equivalent to fseek(fp, 0L,
  6335.         0);.
  6336.  
  6337.         :: NOTE: Refer to the file_pointer manual page for general
  6338.         :: information.
  6339.  
  6340.     INPUTS
  6341.         FILE *fp;     file pointer to rewind
  6342.  
  6343.     RESULTS
  6344.         none
  6345.  
  6346.     SEE ALSO
  6347.         fseek, fgetpos, fsetpos
  6348.  
  6349.     EXAMPLE
  6350.         /*
  6351.         *  print a file 3 times 
  6352.         */
  6353.         #include <stdio.h>
  6354.         main(ac, av) int ac; char **av;
  6355.         {
  6356.            FILE *fp;
  6357.            int i;
  6358.            char buf[256];
  6359.            if (ac == 1)
  6360.            {
  6361.               puts("Expected textfile argument");
  6362.               exit(1);
  6363.            }
  6364.            p = fopen(av[1], "r"); 
  6365.            if (fp == NULL) 
  6366.            {
  6367.               printf("Unable to open %s\n", av[1]);
  6368.               exit(1);
  6369.            }
  6370.            for (i = 1; i <= 3; ++i)
  6371.            {
  6372.               rewind(fp); printf("PRINTING #%d\n", i);
  6373.               while (fgets(buf, sizeof(buf), fp)) 
  6374.                  fputs(buf, stdout); 
  6375.            } 
  6376.            return(0);
  6377.         }
  6378.  
  6379. dice/rmdir                                                        dice/rmdir
  6380.  
  6381.     FUNCTION
  6382.         delete a directory
  6383.  
  6384.     LIBRARY
  6385.         TBA
  6386.  
  6387.     SYNTAX
  6388.         #include <TBA.h>
  6389.         int r = rmdir(dirname);
  6390.         char *dirname;
  6391.  
  6392.     DESCRIPTION
  6393.         rmdir deletes a directory.  The directory must be empty for the
  6394.         deletion to work.  On the Amiga this call is equivalent to remove or
  6395.         unlink.
  6396.  
  6397.     INPUTS
  6398.         char *dirname;     name of directory to delete
  6399.  
  6400.     RESULTS
  6401.         int r;       0 if successful, non-zero if error
  6402.  
  6403.     SEE ALSO
  6404.         mkdir
  6405.  
  6406.     EXAMPLE
  6407.         #include <assert.h>
  6408.         main()
  6409.         {
  6410.            int r;
  6411.            r = mkdir("T:tmpdir");
  6412.            assert(r == 0);
  6413.            r = rmdir("T:tmpdir");
  6414.            assert(r == 0);
  6415.         }
  6416.  
  6417. dice/scanf,fscanf,sscanf                            dice/scanf,fscanf,sscanf
  6418.  
  6419.     FUNCTION
  6420.         scanf: scan formatted text from stdin 
  6421.         fscanf: scan formatted text from a specified file pointer 
  6422.         sscanf: scan formatted text from a string buffer
  6423.  
  6424.     LIBRARY
  6425.         TBA
  6426.  
  6427.     SYNTAX
  6428.         #include <stdio.h>
  6429.         int n = scanf(ctl, ...); 
  6430.         int n = fscanf(fp, ctl, ...); 
  6431.         int n = sscanf(str,ctl, ...);
  6432.         const char *ctl;
  6433.         FILE *fp;
  6434.         char *str;
  6435.  
  6436.     DESCRIPTION
  6437.         These routines scan the specified input file or buffer for fields
  6438.         matching those specified in the ctl field.  The ctl field contains %
  6439.         constructions that relate an argument pointer to the scanned text. 
  6440.         The ctl field may also contain other characters which must match the
  6441.         scanned text exactly, except for a white space character which matches
  6442.         one or more white space characters the scanned text. A % construction
  6443.         in the ctl string is formatted as follows:
  6444.  
  6445.             %[*][nnn][h/l/L]<conversion-specifier>
  6446.             (1) An optional * that tells scanf to skip the specified convresion
  6447.         (i.e. you specify no argument for this conversion).  Skipped
  6448.          conversions are not included in the return count.
  6449.             (2) An optional integer that specifies the maximum field width.
  6450.             (3) An optional modifier h, l, or L:
  6451.                  h  When used with d,i,n,o,u,x,X
  6452.                      specifies the argument is a pointer to a short integer 
  6453.                     rather than an integer.
  6454.                  l   When used with d,i,o,u,x,X
  6455.                     specifies the argument is a pointer to a long integer rather than
  6456.          an
  6457.                     integer.
  6458.                  L  When used with e,E,f,F,G
  6459.                     specifioes the argument is a pointer to a long double rather than
  6460.          a
  6461.                     double.
  6462.              (4) A conversion specifier
  6463.                  c   Converts the number of characters specified by the field width
  6464.                     (default  1) into an array.  The expected argument is a pointer to
  6465.                     an array of characters.
  6466.                  d  Converts a decimal (base 10) number.  The expected argument is
  6467.          a
  6468.                     pointer to an integer.
  6469.                  e/E/f/g scans a floating point number.  If the 'L' modifier is used
  6470.          a long 
  6471.                     double pointer is expected (not implemented in DICE yet). 
  6472.                     Otherwise a double is expected.
  6473.                  i   Converts a number to an integer.  The format should be
  6474.          equivalent to
  6475.                     that expected by strtol with a base argument of 0 (i.e. allows any
  6476.                     base construction).
  6477.                  n   This does not read any text, but stores the number of
  6478.          characters *scanf
  6479.                     has read up to this point into the integer argument.
  6480.                  o   Converts a number to an octal integer.
  6481.                  p   Reads a sequence of characters in the same format as printf's
  6482.          %p
  6483.                     specifier and store into a pointer.  The corresponding argument is
  6484.                     passed as a void **.
  6485.                  s   Reads a string of non-white space characters and copy into the
  6486.          array
  6487.                     specified by the argument.  The argument should be of type (char
  6488.                     *) and have enough space to handle the string plus a NULL
  6489.                     terminator.
  6490.                  x   Reads a base 16 number (hex) and copy into the passed integer. 
  6491.          This is
  6492.                     equivalent to calling strtol with a base of 16.
  6493.                    %  (i.e. %%) matches a single %
  6494.                 [/] Scan a scanset.  Scan the input stream and place the characters
  6495.          into a
  6496.                     char * buffer until a character is read that does not match the
  6497.                     scanset.  If a scan set begins with ^ (as in [^abcd]) then all
  6498.                     characters are allowed EXCEPT those specified in the scanset.  If
  6499.          a
  6500.                     scanset begins as []abcd] or [^]abcd] then the ']' character is
  6501.                     included in the scan set and the set is terminated by the next ']'
  6502.                     character.
  6503.  
  6504.         :: NOTE:  Refer to the file_pointer manual page for general
  6505.         :: information.  All pointers to floating point storage must be
  6506.         :: pointers to doubles.
  6507.  
  6508.     INPUTS
  6509.         char *ctl;      format control string
  6510.  
  6511.         FILE *fp;    (fscanf) file pointer, (read to obtain text to format)
  6512.  
  6513.         char *str;      (sscanf) string pointer, text to format
  6514.  
  6515.     RESULTS
  6516.         int n;      # of conversions that occured, -1 if no conversions could be
  6517.  
  6518.             done (usually means EOF). May return less than the number requested
  6519.  
  6520.             and this value does   not reflect any %* forms.
  6521.  
  6522.     SEE ALSO
  6523.         sprintf, printf, fprintf
  6524.  
  6525.     EXAMPLE
  6526.         /*
  6527.         * NOTE:   unscanned arguments are NOT cleared and
  6528.         * will print out as garbage. 
  6529.         */
  6530.         #include <stdio.h>
  6531.         main(ac, av)
  6532.         int ac; char *av[];
  6533.         {
  6534.            short a[4];
  6535.            int b[2];
  6536.            char buf1[32];
  6537.            char buf2[32];
  6538.            int n;
  6539.            if (ac != 2)
  6540.            {
  6541.               puts("Expected string to format!"); exit(1);
  6542.            }
  6543.            n = sscanf(av[1], "%hd %ho %hi %*hn%d %X %10c%10c",
  6544.         a + 0, a + 1, a + 2, b + 0, b + 1, buf1, buf2   );
  6545.    printf("n =
  6546.          %d\n", n);
  6547.            printf("a: %d %d %d %d\n",  a[0], a[1], a[2], a[3]);
  6548.            printf("b: %d %d\n", b[0], b[1]);  printf("buf1: %s\n", buf1);
  6549.            printf("buf2: %s\n", buf2);
  6550.            return(0);
  6551.         }
  6552.         `
  6553.  
  6554.         1> t:x "123 23 01000 22 0xFF abcdefghijklm as ds sd " 
  6555.         n = 7 a: 123 19 512 12 b: 22 255
  6556.         buf1: abcdefghij buf2: klm as ds
  6557.         1>
  6558.  
  6559. dice/_SearchPath                                            dice/_SearchPath
  6560.  
  6561.     FUNCTION
  6562.         search the current Path for an executable file
  6563.  
  6564.     LIBRARY
  6565.         TBA
  6566.  
  6567.      SYNTAX
  6568.         TBA
  6569.  
  6570.     DESCRIPTION
  6571.         _SearchPath earches the current path for an executable file.
  6572.  
  6573.         || WARNING!  DO NOT EVER USE THIS FUNCTION.  This is an internal DICE
  6574.         || function used by DCC and is subject to change without notice.
  6575.         || _SearchPath can easily break under new versions of the OS and
  6576.         || special care is taken by DCC when using it.  The 2.0 version of the
  6577.         || Amiga operating system has calls that will properly accomplish this
  6578.         || operation.
  6579.  
  6580.     INPUTS
  6581.         TBA
  6582.  
  6583.     RESULTS
  6584.         TBA
  6585.  
  6586.     SEE ALSO
  6587.         _SearchResident
  6588.  
  6589.     EXAMPLE
  6590.         TBA
  6591.  
  6592. dice/_SearchResident                                    dice/_SearchResident
  6593.  
  6594.     FUNCTION
  6595.         search the resident list for an executable
  6596.  
  6597.     LIBRARY
  6598.         TBA
  6599.  
  6600.     DESCRIPTION
  6601.         _SearchResident searches the Resident list for an executable.
  6602.  
  6603.         || WARNING! DO NOT EVER EVER EVER USE THIS FUNCTION.  This is an
  6604.         || internal DICE function used by DCC and is subject to change without
  6605.         || notice. _SearchResident can easily break under new versions of the
  6606.         || OS and special care is taken by DCC when using it.  The 2.0 version
  6607.         || of the Amiga operating system has calls that will properly
  6608.         || accomplish this operation.
  6609.  
  6610.     INPUTS
  6611.         TBA
  6612.  
  6613.     RESULTS
  6614.         TBA
  6615.  
  6616.     SEE ALSO
  6617.         _SearchPath
  6618.  
  6619.     EXAMPLE
  6620.         TBA
  6621.  
  6622. dice/setbuf,setvbuf                                      dice/setbuf,setvbuf
  6623.  
  6624.     FUNCTION
  6625.         set alternative stream buffer
  6626.  
  6627.     LIBRARY
  6628.         TBA
  6629.  
  6630.     SYNTAX
  6631.         #include <stdio.h>
  6632.         void setbuf(fp, buf);
  6633.         FILE *fp; char *buf;
  6634.  
  6635.     DESCRIPTION
  6636.         setbuf changes the internal buffer used by stdio.  The buffer you pass
  6637.         it must be BUFSIZ bytes in size.  You can set a file pointer to
  6638.         unbuffered by passing NULL for your buffer.  setvbuf supersedes this
  6639.         call and is, in general, a better routine.
  6640.  
  6641.         || WARNING!!  If buffering is turned off for a file pointer
  6642.         || representing a console device, the console device is set to be
  6643.         || unbuffered as well.
  6644.  
  6645.         :: NOTE:  Refer to the file_pointer manual page for general
  6646.         :: information.
  6647.  
  6648.     INPUTS
  6649.         FILE *fp;    file pointer to rewind
  6650.  
  6651.         char\*buf;        buffer the file pointer uses instead of its own or NULL
  6652.         to
  6653.  
  6654.         make the file pointer unbuffered.
  6655.  
  6656.     RESULTS
  6657.         none
  6658.  
  6659.     SEE ALSO
  6660.         setvbuf
  6661.  
  6662.     EXAMPLE
  6663.         #include <stdio.h>
  6664.         main()
  6665.         {
  6666.            setbuf(stdout, NULL);
  6667.            printf("This will print immediately because");
  6668.            sleep(1); 
  6669.            printf(" we are unbuffered");
  6670.            sleep(1);
  6671.            puts("");
  6672.            return(0);
  6673.         }
  6674.  
  6675. dice/setjmp,longjmp                                      dice/setjmp,longjmp
  6676.  
  6677.     FUNCTION
  6678.         setjmp: save procedure context for future long jump
  6679.         longjmp: jump to a previously saved procedure context
  6680.  
  6681.     LIBRARY
  6682.         TBA
  6683.  
  6684.     SYNTAX
  6685.         #include <setjmp.h>
  6686.         int r = setjmp(enviro);
  6687.         (void) longjmp(enviro, rval)
  6688.         jmp_buf enviro;
  6689.         int rval;
  6690.  
  6691.     DESCRIPTION
  6692.         First, setjmp stores the current procedure context into an environment
  6693.         array whose type is jmp_buf.  When called by a procedure it saves the
  6694.         environment and returns 0.  Then when called, longjmp jumps to a
  6695.         previously saved environment causing execution to begin at the setjmp
  6696.         call that saved that enviroment. Yet instead of returning 0 the
  6697.         'resumed' setjmp returns a return value set by the longjmp call. 
  6698.         Jmp_buf is a typedef of an array, thus by passing a jmp_buf structure
  6699.         we really pass the address of it.  setjmp and longjmp are fully
  6700.         compatible with dynamic stacks  (-gs option to DCC).
  6701.  
  6702.         || WARNING!  You can only longjmp to a previously saved enviroment
  6703.         || that has not been unstacked.
  6704.  
  6705.         In the example below main is still stacked when the longjmp occurs and
  6706.         is thus valid.  It would be illegal, for instance, to call a
  6707.         subroutine which does a setjmp and RETURNS to you, then longjmp back
  6708.         to that subroutine. The contents of the jmp_buf structure are private
  6709.         and may not be modified by the program.
  6710.  
  6711.         || WARNING!  setjmp saves the current state of the registers, but not
  6712.         || any registers that get modified between the setjmp and the longjmp!
  6713.  
  6714.         Thus, auto variables placed in registers (which is done so
  6715.         automatically under DICE) may contain 'old' values after a longjmp if
  6716.         they were modified after the setjmp. To prevent this such variables
  6717.         must, by ANSI convention, be made volatile.  The volatile qualifier
  6718.         forces an auto variable to be placed on the stack instead of in a
  6719.         register.
  6720.  
  6721.     INPUTS
  6722.         jmp_buf enviro;     enviroment structure
  6723.  
  6724.         int rval;      return value (longjmp call)
  6725.  
  6726.     RESULTS
  6727.         (setjmp) int r;      0 when called directly, rval when enviroment
  6728.         restored
  6729.  
  6730.             by a longjmp
  6731.  
  6732.     SEE ALSO
  6733.         onbreak, signal
  6734.  
  6735.     EXAMPLE
  6736.         /*
  6737.         *  run the program 1> sampleprg, it will print "Break Me With..." 
  6738.         * continuously until you type ^C to break the program. The
  6739.         *  onbreak() vector takes over and longjmp's back to main. 
  6740.         */
  6741.         #include <stdio.h>
  6742.         #include <setjmp.h>
  6743.         jmp_buf x;
  6744.         /*
  6745.          * even though the onbreak call is supposed to return, we can 
  6746.          * longjmp out of it as well. 
  6747.          */
  6748.         int brk(void); 
  6749.         void breakme(void); 
  6750.         main()
  6751.         {
  6752.            int r;
  6753.            onbreak(brk);
  6754.             r = setjmp(x);  
  6755.            /*  returns 0 when called by main */
  6756.            if (r == 0)
  6757.            {
  6758.               for (;;)
  6759.               breakme();
  6760.            } 
  6761.            /* returns rval when longjmp'd to */
  6762.            printf("Broke and jumped, r = %d\n", r);
  6763.            return(0); 
  6764.         }
  6765.         int brk();
  6766.         {
  6767.            longjmp(x, 23);
  6768.         }
  6769.         void breakme();
  6770.         {
  6771.            puts("Break Me With ^C!");
  6772.         }
  6773.  
  6774. dice/setvbuf                                                    dice/setvbuf
  6775.  
  6776.     FUNCTION
  6777.         change file pointer's buffering
  6778.  
  6779.     LIBRARY
  6780.         TBA
  6781.  
  6782.     SYNTAX
  6783.         #include <stdio.h>
  6784.         int error = setvbuf(fp, buf, mode, size);
  6785.         FILE *fp;
  6786.         char *buf;
  6787.         int mode;
  6788.         size_t size;
  6789.  
  6790.     DESCRIPTION
  6791.         setvbuf changes the internal buffer used by stdio.  You may specify a
  6792.         new buffer of any size, change the buffering mode of the file pointer
  6793.         to fully buffered, line buffered, or unbuffered mode:
  6794.  
  6795.              _IOFBF  fully buffered (output flushed only if buffer full)
  6796.             _IOLBF line buffered (output flushed every newline)
  6797.             _IONBF unbuffered (no buffering at all)
  6798.  
  6799.         For _IOFBF and _IOLBF, buf should point to the buffer you wish the
  6800.         file pointer to use and size should be the size of that buffer (any
  6801.         size other than 0 is valid).  For_IONBF the buf and size arguments
  6802.         should be passed as NULL
  6803.  
  6804.         || WARNING!  If buffering is turned off for a file pointer
  6805.         || representing a console device, the console device is set to
  6806.         || unbuffered as well.  If buffering is turned on for a file pointer
  6807.         || representing a console device, the console device is set to
  6808.         || buffered as well.
  6809.  
  6810.     INPUTS
  6811.         FILE *fp;    file pointer to change buffering options on
  6812.  
  6813.         char *buf;     new buffer or NULL (_IONBF)
  6814.  
  6815.         int mode;      buffering mode size
  6816.  
  6817.         _t size;        size of new buffer if not NULL, else 0
  6818.  
  6819.     RESULTS
  6820.         int error;     0 on success, a negative number on error (such as illegal
  6821.         arguments)
  6822.  
  6823.     SEE ALSO
  6824.         setbuf
  6825.  
  6826.     EXAMPLE
  6827.         #include <stdio.h>
  6828.         main()
  6829.         {   
  6830.            int c;
  6831.            static char iobuf[128];
  6832.            char buf[256];
  6833.            setvbuf(stdin, NULL, _IONBF, 0);
  6834.            printf("Type a character: ");
  6835.            fflush(stdout);
  6836.            c = getchar();
  6837.            printf("c = %d\n", c);
  6838.            setvbuf(stdin, iobuf, _IOLBF, sizeof(iobuf));
  6839.            printf("Type a line: ");
  6840.            fflush(stdout);
  6841.            gets(buf); printf("You said:  %s\n", buf);
  6842.            return(0); 
  6843.         }
  6844.  
  6845. dice/signal                                                      dice/signal
  6846.  
  6847.     FUNCTION
  6848.         set a signal vector for a signal
  6849.  
  6850.     LIBRARY
  6851.         TBA
  6852.  
  6853.     SYNTAX
  6854.         #include <TBA.h>
  6855.         typedef void (*__sigfunc)(int);
  6856.         __sigfunc oldfunc = signal(signo, newfunc)
  6857.         int signo;
  6858.         __sigfunc newfunc;
  6859.  
  6860.     DESCRIPTION
  6861.         signal sets a signal vector function for a given signal number as
  6862.         defined in <signal.h> and returns the previously set function.
  6863.         Currently only SIGINT causes any semi-asynchronous action to occur.
  6864.         You may pass newfunc as your own signal function or one of:
  6865.  
  6866.             SIG_ERR    error (exit program)
  6867.  
  6868.             SIG_DFL    default (for break, normal operation)
  6869.  
  6870.             SIG_IGN    ignore signal (for break, ^C is now ignored)
  6871.  
  6872.         when a signal occurs, the signal is set back to its default condition
  6873.         before the handler is called.  Thus, if you are allowing multiple
  6874.         signals to occur you must restore the signal vector with signal from
  6875.         your signal handler before it returns.
  6876.  
  6877.         :: NOTE: On the Amiga, signals are not truly asynchronous.  Currently
  6878.         :: ^C is detected during stdio calls only.  No other signal is
  6879.         :: implemented though you CAN modify any signal vector 0 to 31 and
  6880.         :: raise it with the raise call. Early versions of DICE, including
  6881.         :: quite possibly this version, do not understand complex type
  6882.         :: declarations containing procedural types. Thus, you may have to get
  6883.         :: around the problem by building up a complex procedural type with
  6884.         :: typedefs.  Unlike onbreak, a signal function returns no value.
  6885.  
  6886.     INPUTS
  6887.         int signo;     signal to modify, usually SIGINT __sigfunc
  6888.  
  6889.         newfunc;     signal function or SIG_ERR, SIG_DFL, SIG_IGN
  6890.  
  6891.     RESULTS
  6892.         __sigfunc oldfunc;      previous signal function
  6893.  
  6894.     SEE ALSO
  6895.         raise
  6896.  
  6897.     EXAMPLE
  6898.         #include <signal.h>
  6899.         void brkfunc(int);
  6900.         main()
  6901.         {
  6902.            short i;
  6903.            puts("The following is unbreakable");
  6904.            sleep(1);
  6905.            signal(SIGINT, SIG_IGN);
  6906.            for (i = 0; i < 100; ++i) printf("1 %d\n", i);
  6907.            puts("The following may be broken out of");
  6908.            puts("with a cute message");
  6909.            sleep(1);
  6910.            signal(SIGINT, brkfunc);
  6911.            for (i = 0; i < 100; ++i) printf("2 %d\n", i);
  6912.            puts("The following may be broken out of");
  6913.            sleep(1);
  6914.            signal(SIGINT, SIG_DFL);
  6915.            for (i = 0; i < 100; ++i) printf("3 %d\n", i);
  6916.            puts("Hey! You never hit ^C!  What kind of test is this!");
  6917.            return(0);
  6918.         }
  6919.         void brkfunc(int signo)
  6920.         {
  6921.            printf("signo %d occured, exiting\n", signo);
  6922.            exit(1); 
  6923.         }
  6924.  
  6925. dice/sin,fsin                                                  dice/sin,fsin
  6926.  
  6927.     FUNCTION
  6928.         sin: return sine of a double quantity
  6929.  
  6930.         fsin: return sine of a double quantity return sine of a float quantity
  6931.  
  6932.     LIBRARY
  6933.         TBA
  6934.  
  6935.     SYNTAX
  6936.         #include <math.h>
  6937.         double a = sin(b);
  6938.         double b;
  6939.         float  c = fsin(d);
  6940.         float  d;
  6941.  
  6942.     DESCRIPTION
  6943.         sin returns the sine of a double quantity; fsin returns the sine of a
  6944.         floating point quantity.
  6945.  
  6946.     INPUTS
  6947.         double b;     double floating point value
  6948.  
  6949.         float d;       float floating point value
  6950.  
  6951.     RESULTS
  6952.         double a;     result double floating point value
  6953.  
  6954.         float c;     result float floating point value
  6955.  
  6956.     SEE ALSO
  6957.         acos, asin, atan, cos, exp, fabs, log, log10, pow, sqrt, tan, facos,
  6958.         fasin, ...
  6959.  
  6960.     EXAMPLE
  6961.         TBA
  6962.  
  6963. dice/sleep                                                        dice/sleep
  6964.  
  6965.     FUNCTION
  6966.         sleep for a period of time
  6967.  
  6968.     LIBRARY
  6969.         TBA
  6970.  
  6971.     SYNTAX
  6972.         #include <TBA.h>
  6973.         sleep(n);
  6974.         int n;
  6975.  
  6976.     DESCRIPTION
  6977.         The sleep function waits for a period of time specified in seconds. 
  6978.         It can be interrupted by a ^C.
  6979.  
  6980.         :: NOTE: The timekeeping of sleep is not very accurate.  On the Amiga,
  6981.         :: sleep is implemented with a loop of delay(50); calls.
  6982.  
  6983.     INPUTS
  6984.         int n;         number of seconds to sleep
  6985.  
  6986.     RESULTS
  6987.         none
  6988.  
  6989.     SEE ALSO
  6990.         TBA
  6991.  
  6992.     EXAMPLE
  6993.         #include <stdio.h>
  6994.         main(ac, av)
  6995.         char *av[];
  6996.         {
  6997.            puts("Sleeping for 10 seconds");
  6998.            sleep(10);
  6999.            puts("That was a good rest");
  7000.            return(0);
  7001.         }
  7002.  
  7003. dice/sqrt,fsqrt                                              dice/sqrt,fsqrt
  7004.  
  7005.     FUNCTION
  7006.         sqrt: return the square root of a double quantity 
  7007.         fsqrt: return the square root of a float quantity
  7008.  
  7009.     LIBRARY
  7010.         TBA
  7011.  
  7012.     SYNTAX
  7013.         #include <math.h>
  7014.         double a = sqrt(b);
  7015.         double b;
  7016.         float  c = fsqrt(d);
  7017.         float  d;
  7018.  
  7019.     DESCRIPTION
  7020.         sqrt returns the square root of a double quantity; fsqrt returns the
  7021.         square root of a floating point quantity.
  7022.  
  7023.     INPUTS
  7024.         double b;     double floating point value
  7025.  
  7026.         float d;       float floating point value
  7027.  
  7028.     RESULTS
  7029.         double a;     double floating point value
  7030.  
  7031.         float c;     float floating point value
  7032.  
  7033.     SEE ALSO
  7034.         acos, asin, atan, cos, exp, fabs, log, log10, pow, sin, tan, facos,
  7035.         fasin, ...
  7036.  
  7037.     EXAMPLE
  7038.         /*
  7039.          *  compile with the math library -lm 
  7040.          */ 
  7041.         #include <math.h> 
  7042.         #include <stdio.h> 
  7043.         main() 
  7044.         
  7045.         {
  7046.            {
  7047.               double a = sqrt(0.25); printf("sqrt 0.25 = %lf\n", a);
  7048.               /* 0.5000 */ 
  7049.            } 
  7050.            {
  7051.               /*  less accuracy  */
  7052.               float a = fsqrt(0.25); 
  7053.               printf("sqrt 0.25 = %lf\n", (double)a);
  7054.            }
  7055.            return(0);
  7056.         }
  7057.  
  7058. dice/srand                                                        dice/srand
  7059.  
  7060.     FUNCTION
  7061.         set seed for pseudo-random number
  7062.  
  7063.     LIBRARY
  7064.         TBA
  7065.  
  7066.     SYNTAX
  7067.         #include <stdio.h>
  7068.         #include <stdlib.h>
  7069.         (void) srand(seed)
  7070.         unsigned int seed;
  7071.  
  7072.     DESCRIPTION
  7073.         srand initializes the seed for function rand.
  7074.  
  7075.     INPUTS
  7076.         unsigned int seed;     an unsigned integer used to seed the pseudo-random
  7077.  
  7078.         number generator via srand.
  7079.  
  7080.     RESULTS
  7081.         none
  7082.  
  7083.     SEE ALSO
  7084.         rand
  7085.  
  7086.     EXAMPLE
  7087.         #include <stdio.h>
  7088.         #include <stdlib.h>
  7089.         
  7090.         main(ac, av)
  7091.         char *av[];
  7092.         {
  7093.            short i;
  7094.            short j;
  7095.            if (ac == 2)
  7096.            {
  7097.               int seed =
  7098.               strtol(av[1], NULL, 0);
  7099.               srand(seed);
  7100.               printf("using seed = %d\n",
  7101.               seed);
  7102.            }
  7103.            else
  7104.            {
  7105.            puts("using seed = 1");
  7106.            }
  7107.            for (i = 0; i < 10; ++i)
  7108.            {
  7109.               int n = rand();
  7110.               printf("Random number: %08lx    (%d)\n", n, n);
  7111.            }
  7112.            for (i = 0; i < 31; ++i)
  7113.            {
  7114.               int isone = 0;
  7115.               long mask = 1 << i;
  7116.               for (j = 0; j < 32767; ++j)
  7117.               {
  7118.               if (rand() & mask) ++isone;
  7119.               }
  7120.               printf("bit %d %5d:%-5d (dev %d)\n",  i, 32767 - isone,
  7121.               isone, 16384 -isone);
  7122.            }
  7123.            return(0);
  7124.         }
  7125.  
  7126. dice/stack_abort                                            dice/stack_abort
  7127.  
  7128.     FUNCTION
  7129.         exit point when dynamic stack allocation fails
  7130.  
  7131.     LIBRARY
  7132.         TBA
  7133.  
  7134.     SYNTAX
  7135.         #include <TBA.h>
  7136.         void stack_abort(void)
  7137.         {
  7138.             /* .. your exit code .. */
  7139.             abort();
  7140.         }
  7141.  
  7142.     DESCRIPTION
  7143.         When dynamic stack allocation is enabled via the `-gs option and such
  7144.         an allocation fails, stack_abort is called.  If you do not specify a
  7145.         stack_abort routine, the c.lib stack_abort will be used and simply
  7146.          call abort. 
  7147.         If you do specify a stack_abort routine, you have two choices: you can
  7148.         exit out of the program, or you can simply return from the subroutine
  7149.         which retries the allocation and calls stack_abort again if it
  7150.          fails.
  7151.         The program has about 2KB of stack left at the time this function is
  7152.         called.  Since a low memory condition exists when this function is
  7153.         called you should not do anything that might require additional
  7154.         allocations!
  7155.  
  7156.     INPUTS
  7157.         TBA
  7158.  
  7159.     RESULTS
  7160.         TBA
  7161.  
  7162.     SEE ALSO
  7163.         abort, exit
  7164.  
  7165.     EXAMPLE
  7166.         none - anybody got a good example?
  7167.  
  7168. dice/stat                                                          dice/stat
  7169.  
  7170.     FUNCTION
  7171.         stat a file by name
  7172.  
  7173.     LIBRARY
  7174.         TBA
  7175.  
  7176.     SYNTAX
  7177.         #include <sys/stat.h>
  7178.         int error = stat(name, &stat_buf);
  7179.         const char *name;
  7180.         struct stat stat_buf;
  7181.  
  7182.     DESCRIPTION
  7183.         stat is a UNIX-compatible call that returns information pertaining to
  7184.         the file represented by its name. If 0 is returned, stat succeeded and
  7185.         the fields will be filled in as follows:
  7186.  
  7187.         st_mode    flags:
  7188.         S_IFDIR    if directory
  7189.         S_IFREG    if regular file
  7190.         S_IREAD    if readable
  7191.         S_IWRITE    if writable
  7192.         S_IEXEC    if executable
  7193.         st_size     size of the file, in bytes
  7194.         st_blksize    512 (for now)
  7195.         st_blocks     a guess at the number of actual blocks the file takes up,
  7196.          including headers
  7197.                 and side sectors
  7198.         st_ctime    time the file was last modified
  7199.         st_mtime    same as st_ctime
  7200.         st_dev      physical device ID (do not try to interpret this field, but
  7201.          it does represent
  7202.                 the DOS handler)
  7203.         st_ino      inode ID (usually a file block number on the Amiga)
  7204.  
  7205.         :: NOTE: On the Amiga one normally cannot directly examine a file that
  7206.         :: is exclusively locked.  If this case occurs, stat will attempt to
  7207.         :: scan the parent directory for the file and if that doesn't work,
  7208.         :: returns -1.
  7209.  
  7210.     INPUTS
  7211.         char *name;     name of file to stat
  7212.  
  7213.         struct stat *sbuf;     address of stat structure that will be filled in
  7214.  
  7215.     RESULTS
  7216.         int error;     0 on success, < 0 on error
  7217.  
  7218.     SEE ALSO
  7219.         chdir
  7220.  
  7221.     EXAMPLE
  7222.         #include <stdio.h>
  7223.         #include <fcntl.h>
  7224.         #include <sys/stat.h>
  7225.         main(ac, av)
  7226.         int ac;
  7227.         char *av[];
  7228.         {
  7229.            int r;
  7230.            struct stat stat_buf;
  7231.            if (ac == 1)
  7232.            {
  7233.               puts("test scratch_file");
  7234.               exit(1);
  7235.            }
  7236.            r = stat(av[1], &stat_buf);
  7237.            if (r < 0)
  7238.               printf("Can't stat %s\n", av[1]);
  7239.            else
  7240.               printf("File is %d bytes long\n", stat_buf.st_size);
  7241.            return(0);
  7242.         }
  7243.  
  7244. dice/stdin,stdout,stderr                            dice/stdin,stdout,stderr
  7245.  
  7246.     FUNCTION
  7247.         stdin: standard input channel (file pointer - MACRO)
  7248.         stdout: standard output channel (file pointer - MACRO)
  7249.         stderr: standard error channel (file pointer - MACRO)
  7250.  
  7251.     LIBRARY
  7252.         TBA
  7253.  
  7254.     SYNTAX
  7255.         #include <stdio.h>
  7256.  
  7257.     DESCRIPTION
  7258.         stdin is a FILE * type that represents the program's standard input
  7259.         stream.  This can be redirected via command line redirection when the
  7260.         program is run.  stdout is a FILE * type that represents the program's
  7261.         standard output stream.  This can also be redirected via command line
  7262.         redirection when the program is run.  stderr is a FILE * type that
  7263.         represents the program's standard error stream. Currently stderr is
  7264.         opened by _main and represents the console device associated with the
  7265.         program regardless of standard redirections.  These file pointers may
  7266.         be fclose'd or freopen'd at any time. The stdio macros getchar and
  7267.         putchar and stdio library routines gets and puts deal with stdin and
  7268.         stdout respectively while other library routines such as perror output
  7269.         to stderr.
  7270.  
  7271.     INPUTS
  7272.         TBA
  7273.  
  7274.     RESULTS
  7275.         TBA
  7276.  
  7277.     SEE ALSO
  7278.         gets, puts, getchar, putchar, perror
  7279.  
  7280.     EXAMPLE
  7281.         TBA
  7282.  
  7283. dice/stpcpy                                                      dice/stpcpy
  7284.  
  7285.     FUNCTION
  7286.         copy a string returning a pointer to the end of the destination
  7287.  
  7288.     LIBRARY
  7289.         TBA
  7290.  
  7291.     SYNTAX
  7292.         #include <TBA.h>
  7293.         char *ptr = stpcpy(d, s);
  7294.         char *d;
  7295.         char *s;
  7296.  
  7297.     DESCRIPTION
  7298.         This program copies the NULL terminated string pointed to by s to the
  7299.         buffer d.  The NULL is copied.  A pointer to the NULL character at the
  7300.         end of the copied string in d is returned.
  7301.  
  7302.         :: NOTE:  stpcpy is non-standard.  While a stpcpy/stpcpy combination
  7303.         :: is more efficient than a strcpy/strcat combination, strcpy and
  7304.         :: strcat are standard functions and thus are guaranteed to exist in
  7305.         :: all environments.
  7306.  
  7307.     INPUTS
  7308.         char *d;     pointer to beginning of destination buffer
  7309.  
  7310.         char *s;     pointer to beginning of source string
  7311.  
  7312.     RESULTS
  7313.         char *ptr;     pointer to end of data copied to destination buffer
  7314.  
  7315.     SEE ALSO
  7316.         strcpy, strbpl
  7317.  
  7318.     EXAMPLE
  7319.         #include <stdio.h>
  7320.         #include <string.h>
  7321.         #include <assert.h>
  7322.         main()
  7323.         {
  7324.            char *buf1 = "hello";
  7325.            char *buf2 = "123";
  7326.            char dest[32];
  7327.            char *ptr;
  7328.            ptr = stpcpy(dest, buf1);
  7329.            stpcpy(ptr,  buf2);
  7330.            puts(dest);     /* hello123 */
  7331.            return(0);
  7332.         }
  7333.  
  7334. dice/strbpl                                                      dice/strbpl
  7335.  
  7336.     FUNCTION
  7337.         unpack a string-array buffer into an array of pointers
  7338.  
  7339.     LIBRARY
  7340.         TBA
  7341.  
  7342.      SYNTAX
  7343.         #include <TBA.h>
  7344.         int num = strbpl(av, max, sary)
  7345.         char **av;
  7346.         int max;
  7347.         const char *sary;
  7348.  
  7349.     DESCRIPTION
  7350.         strbpl unpacks a string-array into an array of string pointers.  The
  7351.         string array is a series of NULL terminated strings strung together
  7352.         and terminated by a final NULL.  A pointer to each string is placed in
  7353.         the arary-of-pointers (av) with a final NULL entry assuming the number
  7354.         of strings does not exceed (max-1).
  7355.  
  7356.     INPUTS
  7357.         char **av;     pointer to a preallocated array of pointers
  7358.  
  7359.         int max;     the maximum number of entries in the above array
  7360.  
  7361.         char *sary;     pointer to a packed string.
  7362.  
  7363.     RESULTS
  7364.         int num;     number of pointers loaded into the av array not including
  7365.         the final NULL.  If num == max then the av array was not large enough
  7366.         to fit all the strings or the final NULL.
  7367.  
  7368.     SEE ALSO
  7369.         TBA
  7370.  
  7371.     EXAMPLE
  7372.         #include <stdio.h>
  7373.         #include <string.h>
  7374.         #include <assert.h>
  7375.         main()
  7376.         {
  7377.            char *sary = "this\0is\0a\0test\0\0";
  7378.            char *av[16];
  7379.            int n;
  7380.            #define arysize(x) (sizeof(x)/sizeof((x)[0]))
  7381.            n = strbpl(av, arysize(av), sary);
  7382.            assert(n == 4);       /*  n == 4  */
  7383.            puts(av[0]);           /*  this    */
  7384.            puts(av[1]);           /*  is      */
  7385.            puts(av[2]);           /*  a       */
  7386.            puts(av[3]);           /*  test    */
  7387.            assert(av[4] == NULL); /*  av[4] == NULL   */
  7388.            return(0);
  7389.         }
  7390.  
  7391. dice/strcat                                                      dice/strcat
  7392.  
  7393.     FUNCTION
  7394.         concactenate a string to an existing string
  7395.  
  7396.     LIBRARY
  7397.         TBA
  7398.  
  7399.     SYNTAX
  7400.         #include <TBA.h>
  7401.         char *d = strcat(d, s);
  7402.         char *d;
  7403.         const char *s;
  7404.  
  7405.     DESCRIPTION
  7406.         strcat scans the destination buffer for the NULL terminator and then
  7407.         appends the source string to the destination buffer (removing the NULL
  7408.         terminator and placing one at the end after the concactenation).  A
  7409.         pointer to the beginning of the destination buffer is returned.
  7410.  
  7411.     INPUTS
  7412.         char *d;     pointer to destination buffer which already contains a
  7413.         string (which could be just a \0).
  7414.  
  7415.         char *s;     pointer to the NULL terminated source string
  7416.  
  7417.     RESULTS
  7418.         char *d;     same as the first argument, a pointer to the destination
  7419.         buffer.
  7420.  
  7421.     SEE ALSO
  7422.         strncpy, strcpy, strncat
  7423.  
  7424.     EXAMPLE
  7425.         #include <stdio.h>
  7426.         #include <string.h>
  7427.         #include <assert.h>
  7428.         main()
  7429.         {
  7430.            char d[32];
  7431.            char *s1 = "fu";
  7432.            char *s2 = "bar";
  7433.            char *p;
  7434.            strcpy(d, s1);
  7435.            p = strcat(d, s2);
  7436.            assert(p == d); /*  strcat returns its first argument */
  7437.            puts(d);        /*  fubar       */
  7438.            return(0);
  7439.         }
  7440.  
  7441. dice/strchr                                                      dice/strchr
  7442.  
  7443.     FUNCTION
  7444.         search for a character in a string
  7445.  
  7446.     LIBRARY
  7447.         TBA
  7448.  
  7449.     SYNTAX
  7450.         #include <TBA.h>
  7451.         char *ptr = strchr(s, c)
  7452.         const char *s;
  7453.         int c;
  7454.  
  7455.     DESCRIPTION
  7456.         This searches for the character c within the string pointed to by s. 
  7457.         The terminating NULL at the end of s is included in the search.  A
  7458.         pointer to the first occurance of c in s is returned or NULL if c
  7459.         could not be found. C is converted to a char by strchr before
  7460.         beginning the search.
  7461.  
  7462.         :: NOTE: While strchr(s, 0); may be used to find the end of the string
  7463.         :: this is slow compared to using the construction: `char *ptr = s +
  7464.         :: strlen(s);  /*  ptr = end of string s */.
  7465.  
  7466.     INPUTS
  7467.         char *s;     pointer to the string to search
  7468.  
  7469.         int c;    character to search for.
  7470.  
  7471.     RESULTS
  7472.         char *ptr;     pointer to the first occurance of character c in s or NULL
  7473.         if c could not be found in s.
  7474.  
  7475.     SEE ALSO
  7476.         strrchr
  7477.  
  7478.     EXAMPLE
  7479.         #include <stdio.h>
  7480.         #include <string.h>
  7481.         #include <assert.h>
  7482.         main()
  7483.         {
  7484.            char *s = "this is a test";
  7485.            char *ptr;
  7486.            ptr = strchr(s, 'i');
  7487.            assert(ptr == s + 2);
  7488.            puts(ptr);      /*  "is is a test"  */
  7489.            return(0);
  7490.         }
  7491.  
  7492. dice/strcmp                                                      dice/strcmp
  7493.  
  7494.     FUNCTION
  7495.         compare two strings
  7496.  
  7497.     LIBRARY
  7498.         TBA
  7499.  
  7500.     SYNTAX
  7501.         #include <TBA.h>
  7502.         int r = strcmp(s1, s2);
  7503.         const char *s1;
  7504.         const char *s2;
  7505.  
  7506.     DESCRIPTION
  7507.         strcmp compares two strings, returning -1 if s1 < s2,  0 if s1 == s2 ,
  7508.         and 1 if  s1 > s2.
  7509.  
  7510.         :: NOTE: strcmp converts the chars in the string to unsigned
  7511.         :: quantities when comparing them.  However, for portability you
  7512.         :: should not strcmp strings containing negative characters (bit 7
  7513.         :: set) for anything other than checking the result against 0.  Use
  7514.         :: the memcmp routine instead.
  7515.  
  7516.     INPUTS
  7517.         char *s1;     pointer to first string
  7518.  
  7519.         char *s2;     pointer to second string
  7520.  
  7521.     RESULTS
  7522.         int r;     -1, 0, or 1.
  7523.  
  7524.     SEE ALSO
  7525.         strncmp, stricmp
  7526.  
  7527.     EXAMPLE
  7528.         #include <stdio.h>
  7529.         #include <string.h>
  7530.         #include <assert.h>
  7531.         main()
  7532.         {
  7533.            char *s1 = "abca";
  7534.            char *s2 = "abcd";
  7535.            char *s3 = "abcx";
  7536.            char *s4 = "abcdx";
  7537.            char *s5 = "abc";
  7538.            char *x2 = "abcd";
  7539.            int r;
  7540.            r = strcmp(s2, x2);  
  7541.            /*  string s2 same as string x2 */
  7542.            assert(r == 0);
  7543.            r = strcmp(s2, s1);  
  7544.            /*  string s2 larger than string s1*/
  7545.            assert(r > 0);
  7546.            r = strcmp(s2, s3);
  7547.            assert(r < 0);
  7548.            r = strcmp(s2, s4);
  7549.            assert(r < 0);
  7550.            r = strcmp(s2, s5);
  7551.            assert(r > 0);
  7552.            return(0);
  7553.         }
  7554.  
  7555. dice/strcpy                                                      dice/strcpy
  7556.  
  7557.     FUNCTION
  7558.         copy a string returning a pointer to the beginning of the destination.
  7559.  
  7560.     SYNTAX
  7561.         #include <TBA.h>
  7562.         char *ptr = strcpy(d, s);
  7563.         char *d;
  7564.         char *s;
  7565.  
  7566.     DESCRIPTION
  7567.         strcpy copies the NULL terminated string pointed to by s to the buffer
  7568.         d.  The NULL is copied.  The first argument is returned (a pointer to
  7569.         the buffer d).
  7570.  
  7571.     INPUTS
  7572.         char *d;     pointer to beginning of destination buffer
  7573.  
  7574.         char *s;     pointer to beginning of source string
  7575.  
  7576.     RESULTS
  7577.         char *ptr;     same as the destination buffer pointer (d).
  7578.  
  7579.     SEE ALSO
  7580.         stpcpy
  7581.  
  7582.     EXAMPLE
  7583.         #include <stdio.h>
  7584.         #include <string.h>
  7585.         #include <assert.h>
  7586.         /*
  7587.          *  note that the stpcpy() example accomplishes the same
  7588.          *  thing and is more efficient, but also requires the use
  7589.          *  of a temporary pointer as well as cluttering the source
  7590.          *  and being non-standard.
  7591.          *  strcpy()/strcat() is more portable though less
  7592.          *  efficient.
  7593.          */
  7594.          main()
  7595.         {
  7596.            char *buf1 = "hello";
  7597.            char *buf2 = "123";
  7598.            char dest[32];
  7599.            char *ptr;
  7600.            strcpy(dest, buf1);
  7601.            strcat(dest, buf2);
  7602.            puts(dest);     /* hello123 */
  7603.            return(0);
  7604.         }
  7605.  
  7606. dice/strcspn                                                    dice/strcspn
  7607.  
  7608.     FUNCTION
  7609.         scan a string until a character is found that matches any character in
  7610.         a second string.
  7611.  
  7612.     LIBRARY
  7613.         TBA
  7614.  
  7615.     SYNTAX
  7616.         #include <TBA.h>
  7617.         int len = strcspn(s, toks)
  7618.         const char *s;
  7619.         const char *toks;
  7620.  
  7621.     DESCRIPTION
  7622.         With strcspn, the string s is scanned until a character is found that
  7623.         matches any character in the string toks.  The number of characters
  7624.         skipped is returned.  If no character in s matches any character in
  7625.          toks then the length of the string s is returned. 
  7626.         strcspn is normally used to search for whitespace within a string. 
  7627.         Note that in many cases strpbrk is more useful than strcspn.
  7628.  
  7629.     INPUTS
  7630.         char *s;     pointer to string to scan
  7631.  
  7632.         char *toks;     pointer to string containing characters to compare
  7633.         against
  7634.  
  7635.     RESULTS
  7636.         int len;     # of characters skipped in s before a match was found.
  7637.  
  7638.     SEE ALSO
  7639.         strpbrk, strspn
  7640.  
  7641.     EXAMPLE
  7642.         #include <stdio.h>
  7643.         #include <string.h>
  7644.         #include <assert.h>
  7645.         main()
  7646.         {
  7647.            int len;
  7648.            len = strcspn("hello this is a test", " \tabcd");
  7649.            assert(len == 5);     /*  stopped at the first space  */
  7650.            len = strcspn("hello this is a test", " abl");
  7651.            assert(len == 2);     /*  stopped at the first 'l'    */
  7652.            len = strcspn("hello", "abcd");
  7653.            assert(len == 5);     /*  stopped at end of string 1  */
  7654.            return(0);
  7655.         }
  7656.  
  7657. dice/strdup                                                      dice/strdup
  7658.  
  7659.     FUNCTION
  7660.         duplicate a string using malloc
  7661.  
  7662.     LIBRARY
  7663.         TBA
  7664.  
  7665.     SYNTAX
  7666.         #include <TBA.h>
  7667.         char *s2 = strdup(s1);
  7668.         const char *s1;
  7669.  
  7670.     DESCRIPTION
  7671.         strdup allocates enough space to hold s1 including the terminating
  7672.         NULL and then copies s1 into this space, returning a pointer to the
  7673.         new string.  NULL is returned if space could not be allocated due to
  7674.         low memory conditions.  Note free may be used to free the returned
  7675.         string.  The amount allocated is (strlen(s1) + 1).
  7676.  
  7677.         :: NOTE: This is a non-standard function and may not exist in other C
  7678.         :: environments.
  7679.  
  7680.     INPUTS
  7681.         char *s1;     pointer to the string to duplicate
  7682.  
  7683.     RESULTS
  7684.         char *s2;     pointer to malloc'd space containing a duplicate of the
  7685.          string
  7686.         s1 or NULL if space could not be malloc'd.
  7687.  
  7688.     SEE ALSO
  7689.         malloc, free, strcpy, strlen
  7690.  
  7691.     EXAMPLE
  7692.         #include <stdio.h>
  7693.         #include <string.h>
  7694.         #include <assert.h>
  7695.         /*
  7696.          *  Modifying string constants (quoted strings) may not be
  7697.          *  entirely portable.  Normally one does not use strdup()
  7698.          *  to accomplish the following function but instead
  7699.          *  declares a char array statically initialized with the
  7700.          *  string, such as:
  7701.          *  char FuBar[] = { "This is a test" };
  7702.          *  Which can be modified in a portable fashion without
  7703.          *  having to duplicate the string.
  7704.          */
  7705.         main()
  7706.         {
  7707.            char *s1 = "this is a test";
  7708.            char *s2;
  7709.            s2 = strdup(s1);
  7710.            s2[0] = 'x';
  7711.            puts(s2);   /*  this is a test  */
  7712.            free(s2);
  7713.            s2 = strdup(s1);
  7714.            s2[1] = '0';
  7715.            puts(s2);   /*  this is a test  */
  7716.            free(s2);
  7717.            return(0);
  7718.         }
  7719.  
  7720. dice/strerror                                                  dice/strerror
  7721.  
  7722.     FUNCTION
  7723.         return error string associated with error code
  7724.  
  7725.     LIBRARY
  7726.         TBA
  7727.  
  7728.     SYNTAX
  7729.         #include <TBA.h>
  7730.         const char *str = strerror(error); int error;
  7731.  
  7732.     DESCRIPTION
  7733.         strerror returns a read-only string associated with the specified
  7734.         error, usually taken from errno after some c.lib call fails.  An
  7735.         unknown error will result in the string "unknown error."
  7736.  
  7737.     INPUTS
  7738.         int error;     error code
  7739.  
  7740.     RESULTS
  7741.         char *str;     error string
  7742.  
  7743.     SEE ALSO
  7744.         perror
  7745.  
  7746.     EXAMPLE
  7747.         #include <TBA.h>
  7748.         #include <errno.h>
  7749.         #include <assert.h>
  7750.         main()
  7751.         {
  7752.            FILE *fi;
  7753.            fi = fopen("ThisFileDoesNotExist", "r");
  7754.            assert(fi == NULL);
  7755.            puts(strerror(errno));
  7756.            return(0);
  7757.         }
  7758.  
  7759. dice/strftime                                                  dice/strftime
  7760.  
  7761.     FUNCTION
  7762.         convert broken down time into a string according to a format.
  7763.  
  7764.     LIBRARY
  7765.         TBA
  7766.  
  7767.     SYNTAX
  7768.         #include <TBA.h>
  7769.         size_t len = strftime(buf, max, fmt, tm)
  7770.         char *buf; size_t max;
  7771.         const char *fmt;
  7772.         const struct tm *tm;
  7773.  
  7774.     DESCRIPTION
  7775.         strftime formats a broken down time into a buffer according to a
  7776.         format string fmt.  The fmt string looks like a the format for a
  7777.         printf except with different control definitions:
  7778.  
  7779.              %%  - a literal '%' character
  7780.             %a  - The locale's abbreviated name for the day of week 
  7781.             %A  - The locale's full name for the  day of week 
  7782.             %b - The locale's abbr. name for the month 
  7783.             %B  - The locale's full name for the month 
  7784.             %c  - The locale's default representation for the date & time
  7785.          (ctime)
  7786.             %d  - The day of the month 01-31
  7787.             %H  -The hour 00-23 (24 hour time) 
  7788.             %I  - The hour 01-12  (12 hour time) 
  7789.             %j  - The day in the year 001-366 
  7790.             %m  - The month 01-12 
  7791.             %M  - The minute 00-59 
  7792.             %p - Indication of morning or afternoon.  In the US: "AM" or "PM" 
  7793.             %S - The second 00-59 
  7794.             %U  - The week of the year 00-53, Sunday is the first day in a week 
  7795.             %w - The day of the week 0-6, Sunday=0 (standard) 
  7796.             %W -The day of the week 0-6, monday=0 
  7797.             %x - The locale's default representation for the date only 
  7798.             %X  - The locale's default representation for the time only 
  7799.             %y  - The year mod 100 (00-99) 
  7800.             %Y -The full year (e.g. 1990) 
  7801.             %Z  - The name of the locale's time zone, nothing if unknown
  7802.  
  7803.                     The number of characters written to the string is returned, or 0 if
  7804.         the formatted string exceeds the buffer size.
  7805.  
  7806.         || WARNING! There must be at least max + 1 bytes in buf or unexpected
  7807.         || memory might be overwritten.
  7808.  
  7809.     INPUTS
  7810.         char *buf;     buffer to write formatted string into
  7811.  
  7812.         size_t max;     maximum size of buffer - 1
  7813.  
  7814.         char *fmt;     format string
  7815.  
  7816.         struct tm *tm;     broken down time
  7817.  
  7818.     RESULTS
  7819.         size_t len;     length of formatted string in buffer or 0 if the maximum
  7820.         was exceeded.
  7821.  
  7822.     SEE ALSO
  7823.         time, localtime, asctime, ctime, clock
  7824.  
  7825.     EXAMPLE
  7826.         #include <stdio.h>
  7827.         #include <time.h>
  7828.         
  7829.         main()
  7830.         {
  7831.            time_t t = time(NULL);
  7832.            struct tm *tp = localtime(&t);
  7833.            char buf[256];
  7834.            strftime(buf, sizeof(buf) - 1, "Now is %A %d %B %Y %X",  tp);
  7835.            puts(buf);
  7836.            return(0);
  7837.         }
  7838.  
  7839. dice/stricmp                                                    dice/stricmp
  7840.  
  7841.     FUNCTION
  7842.         compare two strings, case insensitive
  7843.  
  7844.     LIBRARY
  7845.         TBA
  7846.  
  7847.     SYNTAX
  7848.         #include <TBA.h>
  7849.         int r = stricmp(s1, s2);
  7850.         const char *s1;
  7851.         const char *s2;
  7852.  
  7853.     DESCRIPTION
  7854.         stricmp compares two strings, returning: -1 if  s1 < s2, 0 if  s1 ==
  7855.         s2, or 1 if  s1 > s2. differs from strcmp in that case is ignored for
  7856.         alphabetic characters, i.e. a == A.
  7857.  
  7858.         :: NOTE: NOTE= stricmp converts the chars in the string to unsigned
  7859.         :: quantities when comparing them.  However, for portability you
  7860.         :: should not stricmp strings containing negative characters (bit 7
  7861.         :: set) for anything other than checking the result against 0.  Use
  7862.         :: the memcmp routine instead.
  7863.  
  7864.     INPUTS
  7865.         char *s1;     pointer to first string
  7866.  
  7867.         char *s2;     pointer to second string
  7868.  
  7869.     RESULTS
  7870.         int r;     -1, 0, or 1.
  7871.  
  7872.     SEE ALSO
  7873.         strcmp, strncmp
  7874.  
  7875.     EXAMPLE
  7876.         #include <stdio.h>
  7877.         #include <string.h>
  7878.         #include <assert.h>
  7879.         main()
  7880.         {
  7881.            char *s1 = "abCa";
  7882.            char *s2 = "aBcD";
  7883.            char *s3 = "aBCX";
  7884.            char *s4 = "ABCdx";
  7885.            char *s5 = "Abc";
  7886.            char *x2 = "ABCD";
  7887.            int r;
  7888.            r = stricmp(s2, x2); /* string s2 same as string x2 */
  7889.            assert(r == 0);
  7890.            r = stricmp(s2, s1); /* string s2 larger than string s1 */
  7891.            assert(r > 0);
  7892.            r = stricmp(s2, s3);
  7893.            assert(r < 0);
  7894.            r = stricmp(s2, s4);
  7895.            assert(r < 0);
  7896.            r = stricmp(s2, s5);
  7897.            assert(r > 0);
  7898.            return(0);
  7899.         }
  7900.  
  7901. dice/strins                                                      dice/strins
  7902.  
  7903.     FUNCTION
  7904.         insert one string within another
  7905.  
  7906.     LIBRARY
  7907.         TBA
  7908.  
  7909.      SYNTAX
  7910.         #include <TBA.h>
  7911.         void strins(d, s);
  7912.         char *d;
  7913.         const char *s;
  7914.  
  7915.     DESCRIPTION
  7916.         strins inserts string s into d by shifting the string in d over
  7917.         strlen(s) spaces and then copying s into the newly made hold (except
  7918.         for the NULL, of course).  This result is s inserted into d.
  7919.  
  7920.         :: NOTE: There must be enough room in d to insert s; if d is an array
  7921.         :: of 32 chars and contains a string of 8 chars you can insert another
  7922.         :: string of, say, 10 chars, but not of 30 chars.  strins is not an
  7923.         :: ANSI standard function.
  7924.  
  7925.     INPUTS
  7926.         char *d;     destination to insert in front of
  7927.  
  7928.         char *s;     source string to insert
  7929.  
  7930.     RESULTS
  7931.         none
  7932.  
  7933.     SEE ALSO
  7934.         strcpy, strcat, strlen
  7935.  
  7936.     EXAMPLE
  7937.         #include <stdio.h>
  7938.         #include <string.h>
  7939.         main() 
  7940.         {
  7941.            char buf[32];
  7942.            strcpy(buf, "This is a test");
  7943.            strins(buf + 5, "<gak!> ");
  7944.            puts(buf);
  7945.            /*  This <gak!> is a test  */
  7946.            return(0);
  7947.         }
  7948.  
  7949. dice/strlen                                                      dice/strlen
  7950.  
  7951.     FUNCTION
  7952.         returns length of a string
  7953.  
  7954.     LIBRARY
  7955.         TBA
  7956.  
  7957.     SYNTAX
  7958.         #include <TBA.h>
  7959.         int len = strlen(s);
  7960.         const char *s;
  7961.  
  7962.     DESCRIPTION
  7963.         When this function is used, the length of the requested string is
  7964.         returned. The string is scanned until a NULL terminator is found and
  7965.         the number of characters (not including the NULL) is returned.
  7966.  
  7967.     INPUTS
  7968.         char *s;     string to obtain length of
  7969.  
  7970.     RESULTS
  7971.         int len;     length of string
  7972.  
  7973.     SEE ALSO
  7974.         strcpy, strcat
  7975.  
  7976.     EXAMPLE
  7977.         #include <stdio.h>
  7978.         #include <string.h> 
  7979.         #include <assert.h>
  7980.         main()
  7981.         {
  7982.            char buf[32];
  7983.            int len;
  7984.            strcpy(buf, "Fu Bar Bear Boo");
  7985.            len = strlen(buf);
  7986.            assert(len == 15);
  7987.            strcat(buf, "xx");
  7988.            len = strlen(buf);
  7989.            assert(len == 17);
  7990.            return(0);
  7991.         }
  7992.  
  7993. dice/strncat                                                    dice/strncat
  7994.  
  7995.     FUNCTION
  7996.         concactenate a string to an existing string up to a maximum number of
  7997.         characters
  7998.  
  7999.     LIBRARY
  8000.         TBA
  8001.  
  8002.     SYNTAX
  8003.         #include <TBA.h>
  8004.         char *d = strncat(d, s, n);
  8005.         char *d;
  8006.         const char *s;
  8007.         int n;
  8008.  
  8009.     DESCRIPTION
  8010.         strncat scans the destination buffer for the NULL terminator and then
  8011.         appends the source string to the destination buffer (removing the NULL
  8012.         terminator and placing one at the end after the concactenation). 
  8013.         However, only up to n characters is concactenated including the NULL. 
  8014.         If the source string is exactly n characters long no NULL will be
  8015.         appended.  If the source string is longer than n characters then only
  8016.         the first n characters of the source string will be appended (and no
  8017.         NULL will be).  A pointer to the beginning of the destination buffer
  8018.         is returned.
  8019.  
  8020.     INPUTS
  8021.         char *d;     pointer to destination buffer which already contains a
  8022.         string (which could be just a \0).
  8023.  
  8024.         char *s;     pointer to the NULL terminated source string
  8025.  
  8026.         int n;        maximum number of characters to concactenate
  8027.  
  8028.     RESULTS
  8029.         char *d;     same as the first argument, a pointer to the destination
  8030.         buffer.
  8031.  
  8032.     SEE ALSO
  8033.         strncpy, strcpy, strcat
  8034.  
  8035.     EXAMPLE
  8036.         #include <stdio.h>
  8037.         #include <string.h>
  8038.         #include <assert.h>
  8039.         main()
  8040.         {
  8041.            char d[32];
  8042.            char *s1 = "fu";
  8043.            char *s2 = "bar";
  8044.            char *p;
  8045.            d[2] = 23;    d[5] = 24;    d[6] = 25;
  8046.            strcpy(d, s1);
  8047.            /* overwrites d[2] with a NULL  */ 
  8048.            assert(d[2] == 0);
  8049.            p = strncat(d, s2, 3); 
  8050.            /*  does NOT overwrite d[5] with a NULL */
  8051.            assert(d[5] == 24); 
  8052.            assert(p == d);
  8053.            strcpy(d, s1); 
  8054.            p = strncat(d, s2, 20);  /*  does*/
  8055.            assert(p == d);
  8056.            assert(d[5] == 0);
  8057.            assert(d[6] == 25);
  8058.            /* stops at the NULL, so d[6] was not modified */
  8059.            puts(d); 
  8060.            /*  fubar   */
  8061.            return(0);
  8062.         }
  8063.  
  8064. dice/strncmp                                                    dice/strncmp
  8065.  
  8066.     FUNCTION
  8067.         compare two strings up to a maximum number of characters
  8068.  
  8069.     LIBRARY
  8070.         TBA
  8071.  
  8072.     SYNTAX
  8073.         #include <TBA.h>
  8074.         int r = strncmp(s1, s2, n);
  8075.         const char *s1;
  8076.         const char *s2;
  8077.         int n;
  8078.  
  8079.     DESCRIPTION
  8080.         strncmp compares two strings, returning:  -1 if s1 < s2,  0 if s1 ==
  8081.         s2, or 1 if  s1 > s2.   strncmp works like strcmp but only up to n
  8082.         characters will be compared.  If all characters compare when n is
  8083.         reached 0 is returned indicating that the strings matched. Fewer
  8084.         characters might be compared if either string terminates (w/ a NULL)
  8085.         before the maximum is reached or a compare fails (scan is stopped and
  8086.         -1 or 1 is returned immediately).
  8087.  
  8088.         :: NOTE: strncmp converts the chars in the string to unsigned
  8089.         :: quantities when comparing them.  However, for portability you
  8090.         :: should not strncmp strings containing negative characters (bit 7
  8091.         :: set) for anything other than checking the result against 0.  Use
  8092.         :: the memcmp routine instead.
  8093.  
  8094.     INPUTS
  8095.         char *s1;     pointer to first string
  8096.  
  8097.         char * s2;    pointer to second string
  8098.  
  8099.         int n;    maximum number of characters to compare
  8100.  
  8101.     RESULTS
  8102.         int r;       -1, 0, or 1.
  8103.  
  8104.     SEE ALSO
  8105.         stricmp
  8106.  
  8107.     EXAMPLE
  8108.         #include <stdio.h>
  8109.         #include <string.h>
  8110.         #include <assert.h>
  8111.         main()
  8112.         {
  8113.            char *s1 = "abcaq";
  8114.            char *s2 = "abcdr";
  8115.            char  *s3 = "abcxs";
  8116.            char *s4 = "abcdxx";
  8117.            char *s5 = "abc"; 
  8118.            char *x2 = "abcdt"; 
  8119.            int r;   r = strncmp(s2, x2, 4);
  8120.            assert(r == 0); 
  8121.            r = strncmp(s2, s1, 4);
  8122.            assert(r > 0); 
  8123.            r = strncmp(s2, s3, 4); 
  8124.            assert(r < 0);
  8125.            r = strncmp(s2, s4, 8); 
  8126.            assert(r < 0);
  8127.            r = strncmp(s2, s5, 4); 
  8128.            assert(r > 0);
  8129.            return(0);
  8130.         }
  8131.  
  8132. dice/strncpy                                                    dice/strncpy
  8133.  
  8134.     FUNCTION
  8135.         copy a string returning a pointer to the beginning of the destination
  8136.         until NULL or the specified number of characters is reached.
  8137.  
  8138.     LIBRARY
  8139.         TBA
  8140.  
  8141.     SYNTAX
  8142.         #include <TBA.h>
  8143.         char *ptr = strncpy(d, s, n);
  8144.         char *d; 
  8145.         const char *s; 
  8146.         int n;
  8147.  
  8148.     DESCRIPTION
  8149.         strncpy copies the NULL terminated string pointed to by s to the
  8150.         buffer d. The NULL is normally copied.  The first argument is returned
  8151.         (a pointer to the buffer d). The copy will also be terminated if the
  8152.         specified maximum is reached, in which case the NULL is NOT copied.
  8153.  
  8154.     INPUTS
  8155.         char *d;     pointer to beginning of destination buffer
  8156.  
  8157.         char *s;     pointer to beginning of source string
  8158.  
  8159.         int len;       maximum number of characters to copy
  8160.  
  8161.     RESULTS
  8162.         char *ptr;     same as the destination buffer pointer (d).
  8163.  
  8164.     SEE ALSO
  8165.         stpcpy, strcpy
  8166.  
  8167.     EXAMPLE
  8168.         #include <stdio.h>
  8169.         #include <string.h>
  8170.         #include <assert.h>
  8171.         /*
  8172.          *  This is a dumb example 
  8173.          */
  8174.         main()
  8175.         {
  8176.            char *buf1 = "hello";
  8177.            char *buf2 = "123";
  8178.            char dest[32];
  8179.            char *ptr;
  8180.            strncpy(dest, buf1, 8);
  8181.            strcat(dest, buf2);
  8182.            puts(dest); /* hello123 */
  8183.            dest[2] = 23;
  8184.            strncpy(dest, buf1, 2);
  8185.            assert(dest[2] == 23);
  8186.            /* it only copied to chars!     */
  8187.            dest[2] = 0;    /*  note we have to add the NULL */
  8188.            strcat(dest, buf2);
  8189.            /*  he123   */ 
  8190.            puts(dest);
  8191.            return(0); 
  8192.         }
  8193.  
  8194. dice/strnicmp                                                  dice/strnicmp
  8195.  
  8196.     FUNCTION
  8197.         compare two strings up to a maximum number of characters , case
  8198.         insensitive
  8199.  
  8200.     LIBRARY
  8201.         TBA
  8202.  
  8203.     SYNTAX
  8204.         #include <TBA.h>
  8205.         int r = strnicmp(s1, s2, n); 
  8206.         const char *s1; 
  8207.         const char *s2; 
  8208.         int n;
  8209.  
  8210.     DESCRIPTION
  8211.         strnicmp compares two strings, returning:  -1,  s1 < s2;  0, s1 == 
  8212.         s2;   1,  s1 > s2.  strnicmp differs from strcmp in that case is
  8213.         ignored for alphabetic characters (i.e., a == A) and only up to n
  8214.         characters are compared. Refer to stricmp and strncmp for other
  8215.         examples.
  8216.  
  8217.         :: NOTE:  strnicmp converts the chars in the string to unsigned
  8218.         :: quantities when comparing them.  However, for portability you
  8219.         :: should not strnicmp strings containing negative characters (bit 7
  8220.         :: set) for anything other than checking the result against 0.  Use
  8221.         :: the memcmp routine instead.
  8222.  
  8223.     INPUTS
  8224.         char *s1;     pointer to first string
  8225.  
  8226.         char *s2;     pointer to second string
  8227.  
  8228.         int n;         maximum # of characters to compare
  8229.  
  8230.     RESULTS
  8231.         int r;     -1, 0, or 1.
  8232.  
  8233.     SEE ALSO
  8234.         strcmp, strncmp, stricmp
  8235.  
  8236.     EXAMPLE
  8237.         #include <stdio.h>
  8238.         #include <string.h>
  8239.         #include <assert.h>
  8240.         main()
  8241.         {
  8242.            char *s1 = "aBcAQ";
  8243.            char *s2 = "abCDR";
  8244.            char *s3 = "ABcXs";
  8245.            char *s4 = "aBCDxX";
  8246.            char *s5 = "aBC";
  8247.            char *x2 = "AbCDt";
  8248.            int r;
  8249.            r = strnicmp(s2, x2, 4);
  8250.            assert(r == 0);
  8251.            r = strnicmp(s2, s1, 4);
  8252.            assert(r > 0);
  8253.            r = strnicmp(s2, s3, 4);
  8254.            assert(r < 0);
  8255.            r = strnicmp(s2, s4, 8);
  8256.            assert(r < 0);
  8257.            r = strnicmp(s2, s5, 4);
  8258.            assert(r > 0);
  8259.            return(0);
  8260.         }
  8261.  
  8262. dice/strpbrk                                                    dice/strpbrk
  8263.  
  8264.     FUNCTION
  8265.         search for specific character(s) (tokens) in string
  8266.  
  8267.     LIBRARY
  8268.         TBA
  8269.  
  8270.     SYNTAX
  8271.         #include <TBA.h>
  8272.         char *ptr = strpbrk(s, toks)
  8273.         const char *s;
  8274.         char *toks;
  8275.  
  8276.     DESCRIPTION
  8277.         strpbrk searches the string s for any character in the string toks. 
  8278.         For example, when searching for whitespace in s, toks would contain
  8279.         the space and tab character.  If no character in s matches any
  8280.         character in toks then NULL is returned.
  8281.  
  8282.     INPUTS
  8283.         char *s;     pointer to string to scan
  8284.  
  8285.         char *toks;      pointer to string containing tokens to scan for
  8286.  
  8287.     RESULTS
  8288.         char *ptr;     pointer to point in s where the character matches any
  8289.         character
  8290.  
  8291.             in toks, or NULL if s was exhausted.
  8292.  
  8293.     SEE ALSO
  8294.         strtok
  8295.  
  8296.     EXAMPLE
  8297.         #include <stdio.h>
  8298.         #include <string.h>
  8299.         #include <assert.h>
  8300.         main()
  8301.         {
  8302.            char *s = "This  \tis a test";
  8303.            char *ptr;
  8304.            ptr = strpbrk(s, " \t");
  8305.            assert(ptr == s + 4);
  8306.            ptr = strpbrk(ptr + 1, " \t");
  8307.            assert(ptr == s + 5);
  8308.            ptr = strpbrk(ptr + 1, " \t");
  8309.            assert(ptr == s + 6);
  8310.            ptr = strpbrk(ptr + 1, " \t");
  8311.            assert(ptr == s + 9);
  8312.            ptr = strpbrk(ptr + 1, "xyz");  /*  doesn't find 'm */
  8313.            assert(ptr == NULL);
  8314.            return(0);
  8315.         }
  8316.  
  8317. dice/strrchr                                                    dice/strrchr
  8318.  
  8319.     FUNCTION
  8320.         search for a character in a string, scan backwards
  8321.  
  8322.     LIBRARY
  8323.         TBA
  8324.  
  8325.     SYNTAX
  8326.         #include <TBA.h>
  8327.         char *ptr = strrchr(s, c)
  8328.         const char *s;
  8329.         int c;
  8330.  
  8331.     DESCRIPTION
  8332.         strrchr searches for the character c within the string pointed to by
  8333.         s. The terminating NULL at the end of s is included in the search. The
  8334.         string is searched backwards. A pointer to the last occurrance of c in
  8335.         s is returned or NULL if c could not be found.  C is converted to an 8
  8336.         bit quantity by strrchr.
  8337.  
  8338.         :: NOTE:  The ANSI spec does not say anything about including the NULL
  8339.         :: character in the search for strrchr and some implementation may
  8340.         :: thus not implement this properly.
  8341.  
  8342.     INPUTS
  8343.         char *s;     pointer to the string to search
  8344.  
  8345.         int c;     character to search for
  8346.  
  8347.     RESULTS
  8348.         char *ptr;     pointer to the last occurance of character c in s or NULL
  8349.         if c
  8350.  
  8351.             could not be found in s.
  8352.  
  8353.     SEE ALSO
  8354.         strchr
  8355.  
  8356.     EXAMPLE
  8357.         #include <stdio.h>
  8358.         #include <string.h>
  8359.         #include <assert.h>
  8360.         main()
  8361.         {
  8362.            char *s = "this is a test";
  8363.            char *ptr;
  8364.            ptr = strrchr(s, 'i');
  8365.            assert(ptr == s + 5);
  8366.            puts(ptr);      /*  "is a test"  */
  8367.            ptr = strrchr(s, 'x');
  8368.            assert(ptr == NULL);
  8369.            return(0);
  8370.         }
  8371.  
  8372. dice/strspn                                                      dice/strspn
  8373.  
  8374.     FUNCTION
  8375.         scan a string until a character is found that does not match some
  8376.         character in a second string.
  8377.  
  8378.     LIBRARY
  8379.         TBA
  8380.  
  8381.     SYNTAX
  8382.         #include <TBA.h>
  8383.         int len = strspn(s, toks)
  8384.         const char *s;
  8385.         const char *toks;
  8386.  
  8387.     DESCRIPTION
  8388.         The string s is scanned until a character is found that does not match
  8389.         any character in the string toks.  The number of characters skipped is
  8390.         returned.  If every character in s matches some character in toks then
  8391.         the length of the string s is returned.
  8392.  
  8393.         strspn is normally used to skip whitespace within a string.
  8394.  
  8395.     INPUTS
  8396.         char *s;     pointer to string to scan
  8397.  
  8398.         char *toks;     pointer to string containing
  8399.  
  8400.             characters to compare against
  8401.  
  8402.     RESULTS
  8403.         int len;     # of characters skipped in s before a match could not be
  8404.  
  8405.             found
  8406.  
  8407.     SEE ALSO
  8408.         strpbrk, strcspn
  8409.  
  8410.     EXAMPLE
  8411.         #include <stdio.h>
  8412.         #include <string.h>
  8413.         #include <assert.h>
  8414.         
  8415.         main()
  8416.         {
  8417.            int len;
  8418.            len = strspn("  \t \t\t abcde test", " \t ");
  8419.            assert(len == 7); 
  8420.            /*  stopped at the 'a'  */
  8421.            len = strspn("abcd ", " ");
  8422.            assert(len == 0);
  8423.            len = strspn("   \t\t ", " \t");
  8424.            assert(len == 6); 
  8425.            /*  all match, len = strlen(str);  */
  8426.            return(0);
  8427.         }
  8428.  
  8429. dice/strstr                                                      dice/strstr
  8430.  
  8431.     FUNCTION
  8432.         find sub-string within another string
  8433.  
  8434.     LIBRARY
  8435.         TBA
  8436.  
  8437.     SYNTAX
  8438.         #include <TBA.h>
  8439.         char *ptr = strstr(s, sub);
  8440.         const char *s;
  8441.         const char *sub;
  8442.  
  8443.     DESCRIPTION
  8444.         The string s is scanned until the sub-string sub matches the string
  8445.         beginning at the current scan point, and a pointer to the sub-string
  8446.         within s is returned.  If the sub-string could not be found NULL is
  8447.         returned.
  8448.  
  8449.     INPUTS
  8450.         char *s;     pointer to string to scan
  8451.  
  8452.         char *toks;     pointer to string containing characters to compare
  8453.         against
  8454.  
  8455.     RESULTS
  8456.         char *ptr;     point in s where sub string was found or NULL if sub
  8457.         string could not be found.
  8458.  
  8459.     SEE ALSO
  8460.         strpbrk, strcspn
  8461.  
  8462.     EXAMPLE
  8463.         #include <stdio.h>
  8464.         #include <string.h>
  8465.         #include <assert.h>
  8466.         
  8467.         main()
  8468.         {
  8469.            char *s = "abcdefghijklmnopqrstuvwxyz";
  8470.            char *ptr;
  8471.            ptr = strstr(s, "klm");
  8472.            assert(ptr == s + 10);
  8473.            puts(ptr);  /*  klmnopqrstuvwxyz    */
  8474.            return(0);
  8475.         }
  8476.  
  8477. dice/strtod                                                      dice/strtod
  8478.  
  8479.     FUNCTION
  8480.         convert string to fp double
  8481.  
  8482.     LIBRARY
  8483.         TBA
  8484.  
  8485.     SYNTAX
  8486.         #include <TBA.h>
  8487.         double d = strtod(s, &tp);
  8488.         const char *s;
  8489.         char *tp;
  8490.  
  8491.     DESCRIPTION
  8492.         strtod converts a string to a floating point double.  Initial
  8493.         whitespace is skipped.  The format of the fp number in the string is
  8494.         then:
  8495.  
  8496.         {+/-/<nothing>}ddddd[.ddddd][E{+/-/<nothing>}dddd]
  8497.  
  8498.         Example fp strings: " +1.234E-3", "-1234", "6.5676E4", "214.2345"
  8499.  
  8500.     INPUTS
  8501.         char *s;     pointer to string containing fp number
  8502.  
  8503.         char **tp;     pointer to pointer, the pointer is modified to point to
  8504.         the end of the scanned fp number.
  8505.  
  8506.     RESULTS
  8507.         double d;     resulting double
  8508.  
  8509.     SEE ALSO
  8510.         TBA
  8511.  
  8512.     EXAMPLE
  8513.         /*
  8514.          *  compile -lm to include math library
  8515.          */
  8516.         #include <stdio.h>
  8517.         #include <string.h>
  8518.         
  8519.         main()
  8520.         {
  8521.            double d;
  8522.            char *tp;
  8523.            d = strtod("1.2134 3.45E2", &tp);
  8524.            printf("1.2134 = %lf\n", d);    /*  1.213400    */
  8525.            d = strtod(tp, &tp);
  8526.            printf("3.45E2 = %lf\n", d);    /*  345.000000  */
  8527.            return(0);
  8528.         }
  8529.  
  8530. dice/strtok                                                      dice/strtok
  8531.  
  8532.     FUNCTION
  8533.         break up a string into arguments
  8534.  
  8535.     LIBRARY
  8536.         TBA
  8537.  
  8538.     SYNTAX
  8539.         #include <TBA.h>
  8540.         char *arg = strtok(s, toks)
  8541.         char *s;
  8542.         const char *toks;
  8543.  
  8544.     DESCRIPTION
  8545.         strtok breaks up a string into arguments.  It determines the break
  8546.         point from the toks string which contains a set of whitespace
  8547.         characters (usually \t to mean space and tab).  The first call to
  8548.         strtok should specify the string s and toks. Initial whitespace is
  8549.         skipped and the string is then scanned until the end of the first
  8550.         argument is found.  The string is then modified: a NULL is placed at
  8551.         the end of the first argument and a pointer to the beginning of the
  8552.         first argument is returned.
  8553.  
  8554.         Further calls to strtok should pass a NULL for the string s, which
  8555.         tells strtok to continue scanning the original string (whose pointer
  8556.         was stored in a static char * within strtok). strtok returns arguments
  8557.         until the string is exhausted, in which case it returns NULL.  The
  8558.         initial call to strtok can return NULL if the passed string s contains
  8559.         nothing but whitespace (as specified by toks).  You can change the
  8560.         toks string at any time (i.e. pass a different toks string to strtok).
  8561.  
  8562.         || WARNING! strtok modifies the source string and returns pointers
  8563.         || into it.
  8564.  
  8565.     INPUTS
  8566.         char *s;     pointer to string to parse
  8567.  
  8568.         char *toks;      pointer to string containing whitespace characters
  8569.         (argument delimiters)
  8570.  
  8571.     RESULTS
  8572.         char *arg;     pointer into s to next argument that is NULL terminated (s
  8573.         is modified).
  8574.  
  8575.     SEE ALSO
  8576.         strspn, strcspn
  8577.  
  8578.     EXAMPLE
  8579.         #include <stdio.h>
  8580.         #include <string.h>
  8581.         
  8582.         main()
  8583.         {
  8584.            char buf[32];
  8585.            char *arg;
  8586.            const char *ws = " \t";
  8587.            /*
  8588.             *  'This' 'is' 'a' 'test!'
  8589.             */
  8590.            strcpy(buf, "  This  is \t \t a test!");
  8591.            for (arg = strtok(buf, ws); arg; arg = strtok(NULL, ws))
  8592.            {
  8593.               printf("arg = '%s'\n", arg);
  8594.            }
  8595.            return(0);
  8596.         }
  8597.  
  8598. dice/strtol                                                      dice/strtol
  8599.  
  8600.     FUNCTION
  8601.         convert string to integer
  8602.  
  8603.     LIBRARY
  8604.         TBA
  8605.  
  8606.     SYNTAX
  8607.         #include <TBA.h>
  8608.         long v = strtol(str, &tail, base);
  8609.         const char *str;
  8610.         char *tail;
  8611.         int base;
  8612.  
  8613.     DESCRIPTION
  8614.         strtol converts a string into an integer using the specified base
  8615.         0-36.  If a non-zero base is specified conversion is done using that
  8616.         base (hex numbers may still be preceeded by '0x' or '0X').  If 0 is
  8617.         specified for the base then the base is determined from the first one
  8618.         or two characters of the number portion of the string:
  8619.  
  8620.         
  8621.              0    octal
  8622.             1-9    decimal
  8623.             0x    hex (0x or 0X)
  8624.  
  8625.         For bases larger than 10, alphabetic characters are used to represent
  8626.         digits. Either lower case or upper case letters may be used.  strtol
  8627.         stores a pointer to the remainder of the string after the conversion. 
  8628.         strtol ignores any whitespace at the beginning of the string and also
  8629.         handles an optional negative sign (which may precede the numerical
  8630.          portion of the string). 
  8631.         If successful strtol returns the converted value as a long, 0 if it
  8632.         was unable to convert anything, and an undefined result if the
  8633.         converted value was out of range.
  8634.  
  8635.         :: NOTE:  strtol supersedes atoi and atol.
  8636.  
  8637.     INPUTS
  8638.         char *str;     pointer to string to convert
  8639.  
  8640.         char **tail;     *tail modified to point to just after last character
  8641.         converted
  8642.  
  8643.         int base;     base of conversion or 0 for autoselect
  8644.  
  8645.     RESULTS
  8646.         long v;     converted result, an integer, or 0 if no conversion could be
  8647.         done.
  8648.  
  8649.     SEE ALSO
  8650.         atoi, atol
  8651.  
  8652.     EXAMPLE
  8653.         #include <stdio.h>
  8654.         #include <string.h>
  8655.         
  8656.         main(ac, av)
  8657.         char *av[];
  8658.         {
  8659.            long v;
  8660.            char *tail;
  8661.            if (ac != 3)
  8662.            {
  8663.               puts("testprg <string> <base>");
  8664.               puts("testprg 0123abc 0");
  8665.               puts("testprg 0x1000 0");
  8666.               puts("testprg 0123abc 16");
  8667.               exit(1);
  8668.            }
  8669.            v = strtol(av[1], &tail, atoi(av[2]));
  8670.            printf("v = %d, tail = %s\n", v, tail);
  8671.            return(0);
  8672.         }
  8673.         `1> testprg fffg 16 v = 4095, tail = g 
  8674.         1> testprg -0x100 0  v = -256, tail = 
  8675.         1> testprg 118 8 v = 9, tail = 8
  8676.         1> testprg 11 0 v = 11, tail = 
  8677.         1> testprg 011xx 0 v = 9,  tail = xxx
  8678.  
  8679. dice/system                                                      dice/system
  8680.  
  8681.     FUNCTION
  8682.         call system shell with command line
  8683.  
  8684.     LIBRARY
  8685.         TBA
  8686.  
  8687.     SYNTAX
  8688.         #include <stdio.h>
  8689.         #include <stdlib.h>
  8690.         int r = system(buf);
  8691.         const char *buf;
  8692.  
  8693.     DESCRIPTION
  8694.         `system calls the system shell with the specified command line,
  8695.         returning the exit code of the command or -1 if it was unable to run
  8696.         the command.
  8697.  
  8698.         :: FOR PROGRAMS COMPILED UNDER 1.3, even if run in 1.4 enviroment, the
  8699.         :: system call will not return the exit code from the command, but
  8700.         :: return -1 if could not be run, 0 if it
  8701.  
  8702.         :: FOR PROGRAMS COMPILED UNDER 2.0, system will use the 2.0 calls and
  8703.         :: return a proper exit code when running under 2.0, and will use
  8704.         :: execute if running under 1.3.
  8705.  
  8706.     INPUTS
  8707.         char *buf;     command line to run, like a normal AmigaDOS CLI
  8708.  
  8709.             command line.
  8710.  
  8711.     RESULTS
  8712.         int r;     return code
  8713.  
  8714.     SEE ALSO
  8715.         TBA
  8716.  
  8717.     EXAMPLE
  8718.         TBA
  8719.  
  8720. dice/tan,ftan                                                  dice/tan,ftan
  8721.  
  8722.     FUNCTION
  8723.         tan: return tan of a double quantity;
  8724.  
  8725.         ftan: return tan of a float quantity
  8726.  
  8727.     LIBRARY
  8728.         TBA
  8729.  
  8730.     SYNTAX
  8731.         #include <math.h>
  8732.         double a = tan(b); double b;
  8733.         float  c = ftan(d); float  d;
  8734.  
  8735.     DESCRIPTION
  8736.         tan returns the tangent of a double quantity; ftan returns the tangent
  8737.         of a floating point quantity.
  8738.  
  8739.     INPUTS
  8740.         double b;     double floating point value
  8741.  
  8742.         float d;     float floating point value
  8743.  
  8744.     RESULTS
  8745.         double a;     double floating point value
  8746.  
  8747.         float c;     float floating point value
  8748.  
  8749.     SEE ALSO
  8750.         acos, asin, atan, cos, exp, fabs, log, log10, pow, sin, sqrt, tan
  8751.         facos, fasin, ...
  8752.  
  8753.     EXAMPLE
  8754.         /*
  8755.          *  compile with the math library -lm 
  8756.          */
  8757.         #include <math.h>
  8758.         #include <stdio.h>
  8759.         main()
  8760.         {
  8761.            {
  8762.               double a = tan(0.25); 
  8763.               printf("tan 0.25 = %lf\n", a);
  8764.               /* 0.2553 */
  8765.            {
  8766.            {
  8767.               /*  less accuracy   */
  8768.               float a = ftan(0.25); 
  8769.               printf("tan 0.25 = %lf\n", (double)a);
  8770.            }
  8771.            return(0);
  8772.         }
  8773.  
  8774. dice/time                                                          dice/time
  8775.  
  8776.     FUNCTION
  8777.         get current time
  8778.  
  8779.     LIBRARY
  8780.         TBA
  8781.  
  8782.     SYNTAX
  8783.         #include <TBA.h>
  8784.         time_t t = time(NULL);
  8785.         or time(&t);
  8786.         time_t t;
  8787.  
  8788.     DESCRIPTION
  8789.         time returns the current time as a time_t and also copies it into a
  8790.         time_t if the address of said is passed as an argument. You may pass
  8791.         NULL as an argument in which case the time is only returned.
  8792.  
  8793.         The time is returned as seconds since some base date, time_t is
  8794.         normally an unsigned long.
  8795.  
  8796.     INPUTS
  8797.         time_t *t;     pointer to a time_t or NULL
  8798.  
  8799.     RESULTS
  8800.         time_t t;     a time_t
  8801.  
  8802.     SEE ALSO
  8803.         time, localtime, asctime, strftime, ctime, clock
  8804.  
  8805.     EXAMPLE
  8806.         #include <stdio.h>
  8807.         #include <time.h>
  8808.         
  8809.         main()
  8810.         {
  8811.            time_t t = time(NULL);
  8812.            printf("t = %u\n", t);
  8813.            return(0);
  8814.         }
  8815.  
  8816. dice/tmpfile                                                    dice/tmpfile
  8817.  
  8818.     FUNCTION
  8819.         create a temporary file
  8820.  
  8821.     SYNTAX
  8822.         #include <stdio.h>
  8823.         FILE *fp = tmpfile(void);
  8824.  
  8825.     DESCRIPTION
  8826.         tmpfile creates a temporary file and returns a file pointer.  The name
  8827.         of the file is not accessible. The file pointer is available or
  8828.         reading, writing, and seeking (as in rewind, fseek).  The file is
  8829.         initially empty.  This call may be used to create a temporary file
  8830.         that will automatically be removed when you fclose it.  tmpfile
  8831.         returns a FILE * pointer or NULL if it was unable to create the file.
  8832.  
  8833.     INPUTS
  8834.         none
  8835.  
  8836.     RESULTS
  8837.         FILE *fp;     opened temporary file
  8838.  
  8839.     SEE ALSO
  8840.         tmpnam, fopen, fclose
  8841.  
  8842.     EXAMPLE
  8843.         #include <stdio.h>
  8844.         #include <assert.h>
  8845.         main()
  8846.         {
  8847.            FILE *fp = tmpfile();
  8848.            char buf[256];
  8849.            assert(fp);
  8850.            fputs("This is a test of\n"
  8851.                     "a temporary file\n"
  8852.                     "fubar bletch\n", fp);
  8853.            rewind(fp);
  8854.            while (fgets(buf, sizeof(buf), fp))
  8855.            {
  8856.               fputs(buf, stdout);
  8857.            }
  8858.            fclose(fp);    /* close and delete the file   */
  8859.            return(0);
  8860.         }
  8861.  
  8862. dice/tmpnam                                                      dice/tmpnam
  8863.  
  8864.     FUNCTION
  8865.         create a unique, temporary file name
  8866.  
  8867.     LIBRARY
  8868.         TBA
  8869.  
  8870.     SYNTAX
  8871.         #include <stdio.h>
  8872.         char *filename = tmpnam(buf);
  8873.         char *buf;
  8874.  
  8875.     DESCRIPTION
  8876.         tmpnam creates a unique temporary file name meant never to be seen by
  8877.         the user.  The filename tmpnam creates will be no more than L_tmpnam
  8878.         bytes long (L_tmpnam is a macro in <stdio.h>), including the NULL so
  8879.          you can simply declare a buffer:`char buf[L_tmpnam];.
  8880.         tmpnam returns the buffer into which it created the temporary file
  8881.         name.  If you specify a non-NULL buffer it returns its first argument.
  8882.         If you pass NULL to tmpnam then tmpnam will use its down internal
  8883.         static buffer (overwritting any previous name that was stored in said
  8884.         buffer) and return a pointer to that.
  8885.  
  8886.     INPUTS
  8887.         char *buf;      optional buffer of at least L_tmpnam bytes to hold the
  8888.         temporary file name or NULL to have tmpnam() use its own internal
  8889.         buffer.
  8890.  
  8891.     RESULTS
  8892.         char *ptr;     pointer to buffer (buf if buf != NULL)
  8893.  
  8894.     SEE ALSO
  8895.         tmpfile
  8896.  
  8897.     EXAMPLE
  8898.         #include <stdio.h>
  8899.         #include <assert.h>
  8900.         main()
  8901.         {
  8902.            char buf[L_tmpnam];    char *ptr;
  8903.            ptr = tmpnam(NULL);    puts(ptr);
  8904.            assert(tmpnam(buf) == buf); 
  8905.            /*  returns argument */
  8906.            puts(buf);     /*  haven't overwritten it yet */ 
  8907.            printf("%s (same as first)\n", ptr);
  8908.            assert(tmpnam(NULL) == ptr);
  8909.            /*  that will overwrite it! */
  8910.            puts(ptr);
  8911.            return(0);
  8912.         }
  8913.  
  8914. dice/tolower                                                    dice/tolower
  8915.  
  8916.     FUNCTION
  8917.         convert a character into lower case
  8918.  
  8919.     LIBRARY
  8920.         TBA
  8921.  
  8922.     SYNTAX
  8923.         #include <TBA.h>
  8924.         int lc = tolower(c);
  8925.         int c;
  8926.  
  8927.         :: NOTE: This is a MACRO if you #include <ctype.h>, a subroutine call
  8928.         :: if you do not.
  8929.  
  8930.     DESCRIPTION
  8931.         With tolower, if the character is in upper case the equivalent lower
  8932.         case character is returned, or else the argument is returned (i.e. no
  8933.         change).
  8934.  
  8935.         :: NOTE: When a non-zero value is returned, this value can be anything
  8936.         :: other than zero.  It is not necessarily a 1.  It is guaranteed to
  8937.         :: fit in a short, however, and still remain non-zero. Characters in
  8938.         :: the 128-255 range are valid inputs.  Characters less than   -1 or
  8939.         :: larger than 255 are illegal and the results will be random.  If you
  8940.         :: are passing a CHAR, you must cast it to an UNSIGNED CHAR first. 
  8941.         :: EOF is a valid input an always returns false.
  8942.  
  8943.     INPUTS
  8944.         int c;     character that we are checking
  8945.  
  8946.     RESULTS
  8947.         int r;     converted character
  8948.  
  8949.     SEE ALSO
  8950.         isalnum, isalpha, iscntrl, isdigit, isgraph, islower, isprint,
  8951.         ispunct, isspace, isupper, isxdigit, tolower, toupper
  8952.  
  8953.     EXAMPLE
  8954.         #include <stdio.h>
  8955.         #include <ctype.h>
  8956.         main()
  8957.         {
  8958.            printf("%c%c%c%c", tolower('a'), tolower('B'),
  8959.            tolower('%'), tolower('Q'));
  8960.         }
  8961.  
  8962. dice/toupper                                                    dice/toupper
  8963.  
  8964.     FUNCTION
  8965.         converts a character into upper case
  8966.  
  8967.     LIBRARY
  8968.         TBA
  8969.  
  8970.     SYNTAX
  8971.         #include <TBA.h>
  8972.         int lc = toupper(c);
  8973.         int c;
  8974.  
  8975.         :: This is a MACRO if you #include <ctype.h>, a subroutine call if you
  8976.         :: do not.
  8977.  
  8978.     DESCRIPTION
  8979.         With toupper, if the character is in lower case the equivalent upper
  8980.         case character is returned, or else the argument is returned (i.e. no
  8981.         change).
  8982.  
  8983.         :: NOTE: When a non-zero value is returned, this value can be ANYTHING
  8984.         :: other than zero.  It is not necessarily a 1.  It is guaranteed to
  8985.         :: fit in a short, however, and still remain non-zero. Characters in
  8986.         :: the 128-255 range are valid inputs. characters less than -1 or
  8987.         :: larger than 255 are illegal and the results will be random.  If you
  8988.         :: are passing a CHAR, you must cast it to an UNSIGNED CHAR first. 
  8989.         :: EOF is a valid input an always returns false.
  8990.  
  8991.     INPUTS
  8992.         int c;     character that we are checking
  8993.  
  8994.     RESULTS
  8995.         int r;     converted character
  8996.  
  8997.     SEE ALSO
  8998.         isalnum, isalpha, iscntrl, isdigit, isgraph, islower, isprint,
  8999.         ispunct, isspace, isupper, isxdigit, tolower, toupper
  9000.  
  9001.     EXAMPLE
  9002.         #include <stdio.h>
  9003.         #include <ctype.h>
  9004.         
  9005.         main()
  9006.         {
  9007.            printf("%c%c%c%c", toupper('a'), toupper('B'),
  9008.            toupper('%'), toupper('Q'));
  9009.         }
  9010.  
  9011. dice/ungetc                                                      dice/ungetc
  9012.  
  9013.     FUNCTION
  9014.         push a character back onto a file pointer's input stream
  9015.  
  9016.     LIBRARY
  9017.         TBA
  9018.  
  9019.     SYNTAX
  9020.         #include <stdio.h>
  9021.         int r = ungetc(c, fp);
  9022.         int c;
  9023.         FILE *fp;
  9024.  
  9025.     DESCRIPTION
  9026.         ungetc pushes the specified character back onto the input stream, as
  9027.         if it had not been read.  Only ONE character may be pushed back onto
  9028.         an input stream at a time.  If all went well, the return value r is
  9029.         equal to c.  Else EOF is returned if too many characters were pushed
  9030.         back. Some implementations of C allow multiple characters to be pushed
  9031.          back.  The majority, including DICE, allows only one.
  9032.         ungetc is useful when, in scanning an input stream, you overshoot the
  9033.         'last' character you wanted a particular routine to retrieve.  This
  9034.         routine can push the character back onto the input stream with ungetc
  9035.         so another routine's getc (getchar, fread, fgetc, etc...) will get
  9036.         that character back.
  9037.  
  9038.     INPUTS
  9039.         int c;     character to push back onto input stream
  9040.  
  9041.         FILE *fp;     file pointer stream to push character on to.
  9042.  
  9043.     RESULTS
  9044.         int r;     pushed character (c) if no error, EOF if error
  9045.  
  9046.     SEE ALSO
  9047.         getc, getchar, fread, fgetc
  9048.  
  9049.     EXAMPLE
  9050.         #include <stdio.h>
  9051.         #include <ctype.h>
  9052.         main()
  9053.         {
  9054.            char buf[256];
  9055.            void scan_number();
  9056.            void scan_alpha();
  9057.            puts("Enter nnnaaannn where n=digit a=alpha.
  9058.                     Example: 1234abcd99");
  9059.            printf("? "); 
  9060.            fflush(stdout);
  9061.            scan_number();  puts("--");
  9062.            scan_alpha();   puts("--");
  9063.            scan_number(); return(0);
  9064.         }
  9065.         static void scan_number()
  9066.         {
  9067.            short c;
  9068.            for (c = getchar(); c >= '0' && c <= '9';
  9069.                  c = getchar())
  9070.            {
  9071.                printf("digit: %c\n", c);
  9072.            }
  9073.            if (c != EOF)
  9074.               ungetc(c, stdin); 
  9075.         }
  9076.  
  9077.         static void scan_alpha()
  9078.         {
  9079.            short c;
  9080.            for (c = getchar();
  9081.            tolower(c) >= 'a' && tolower(c) <= 'z'; 
  9082.            c =getchar())
  9083.            {
  9084.               printf("alpha: %c\n", c); 
  9085.            }
  9086.               if (c != EOF) ungetc(c, stdin); 
  9087.         }
  9088.         
  9089.         1> testprg
  9090.         Enter nnnaaannn where n=digit a=alpha.
  9091.         Example: 1234abcd99
  9092.         ? 98charlie55
  9093.         digit: 9
  9094.         digit: 8
  9095.         --
  9096.         alpha: c
  9097.         alpha: h
  9098.         alpha: a
  9099.         alpha: r
  9100.         alpha: l
  9101.         alpha: i
  9102.         alpha: e
  9103.         --
  9104.         digit: 5
  9105.         digit: 5
  9106.         
  9107.         1>
  9108.  
  9109. dice/unlink                                                      dice/unlink
  9110.  
  9111.     FUNCTION
  9112.         delete a file
  9113.  
  9114.     LIBRARY
  9115.         TBA
  9116.  
  9117.     SYNTAX
  9118.         #include <TBA.h>
  9119.         int r = unlink(filename);
  9120.         char *filename;
  9121.  
  9122.     DESCRIPTION
  9123.         unlink deletes a file, equivalent to remove. This call deletes a file
  9124.         from the filesystem.  unlink exists for UNIX compatibility only. Use
  9125.         rmdir to delete a directory if you wish to maintain portability.
  9126.  
  9127.      INPUTS
  9128.         char *filename;     name of file to delete
  9129.  
  9130.     RESULTS
  9131.         int r;       0 if successful, non-zero if error
  9132.  
  9133.     SEE ALSO
  9134.         close, creat, fcntl, fdtofh, ioctl, isatty, lseek, mkdir, open, read,
  9135.         rmdir, unlink, write
  9136.  
  9137.     EXAMPLE
  9138.         main()
  9139.         {
  9140.            int r;
  9141.            r = unlink("T:xx");
  9142.            if (r == 0)
  9143.               puts("deleted T:xx");
  9144.            else
  9145.               puts
  9146.              ("unable to delete t:xx or it does not exist"); 
  9147.         }
  9148.  
  9149. dice/wbmain                                                      dice/wbmain
  9150.  
  9151.     FUNCTION
  9152.         main program entry when run from WORKBENCH
  9153.  
  9154.     LIBRARY
  9155.         TBA
  9156.  
  9157.     SYNTAX
  9158.         #include <TBA.h>
  9159.         int wbmain(struct WBStartup *wbs)
  9160.         {
  9161.             /*  your main code goes here */ 
  9162.             return(exitcode);
  9163.         }
  9164.  
  9165.     DESCRIPTION
  9166.         The wbmain routine is the entry point called after normal
  9167.         initialization of c.lib and the program enviroment is done by the
  9168.         startup module (c.o) and _main() routine (in c.lib). wbmain is called
  9169.         when the program is run from the workbench, main is called when the
  9170.         program is run from the CLI.  Currently the exit code is ignored. The
  9171.         standard workbench startup message is passed to wbmain, you can
  9172.         process or ignore this message as you like but should NOT ReplyMsg it.
  9173.         I repeat, do not ReplyMsg it.  When you return from wbmain or exit out
  9174.         of the program the exit code will automatically deal with the message.
  9175.  
  9176.     INPUTS
  9177.         TBA
  9178.  
  9179.     RESULTS
  9180.         TBA
  9181.  
  9182.     SEE ALSO
  9183.         main
  9184.  
  9185.     EXAMPLE
  9186.         /*
  9187.         *  If run from the workbench this program will create a
  9188.         *  file T:XX instead of printing something on the console
  9189.         *  (since there is no console in that case).
  9190.         */
  9191.         #include <stdio.h>
  9192.         int main(ac, av)
  9193.         int ac;
  9194.         char **av;
  9195.         {
  9196.            puts("This was run from a CLI");
  9197.            return(0);
  9198.         }
  9199.  
  9200.         int wbmain(msg)
  9201.         void *msg;
  9202.         /*  to make the example less complex */
  9203.         {
  9204.            FILE *fi = fopen("T:xx", "w");
  9205.            fprintf(fi, "This was run from the WORKBENCH\n");
  9206.            fclose(fi);
  9207.         }
  9208.  
  9209. dice/write                                                        dice/write
  9210.  
  9211.     FUNCTION
  9212.         write data to a file
  9213.  
  9214.     LIBRARY
  9215.         TBA
  9216.  
  9217.     SYNTAX
  9218.         #include <TBA.h>
  9219.         int r = write(fd, buf, bytes);
  9220.         int fd;
  9221.         void *buf;
  9222.         int bytes;
  9223.  
  9224.     DESCRIPTION
  9225.         write writes data to a file, starting at the current seek position. 
  9226.         It extends the file if necessary, or else writes over existing data.
  9227.         With normal files, write will always return the number of bytes
  9228.         requested and fewer only if an error occurs.  With devices write may
  9229.         or may not return the number of bytes requested depending on the
  9230.         device, though usually it does.
  9231.  
  9232.         :: NOTE: Refer to the file_descriptor manual page for general
  9233.         :: information. Unlike file pointers and file handles, the file
  9234.         :: descriptor is checked for validity and will simply return an error
  9235.         :: if illegal.
  9236.  
  9237.     INPUTS
  9238.         int fd;     file descriptor to write to void
  9239.  
  9240.         *buf;        pointer to buffer to write data from
  9241.  
  9242.         int len;      number of bytes to write
  9243.  
  9244.     RESULTS
  9245.         int r;     number of bytes actually written, usually an error if r !=len.
  9246.  
  9247.     SEE ALSO
  9248.         close, creat, fcntl, fdtofh, ioctl, isatty, lseek, mkdir, open, read,
  9249.         rmdir, unlink
  9250.  
  9251.     EXAMPLE
  9252.         #include <fcntl.h>
  9253.         #include <assert.h>
  9254.         
  9255.         main()
  9256.         {
  9257.            int fd;
  9258.            int r;
  9259.            fd = open("T:xx", O_WRONLY|O_CREAT|O_TRUNC);
  9260.            assert(fd >= 0);
  9261.            r =  write(fd, "FuBar\n", 6);
  9262.            assert(r == 6);
  9263.            lseek(fd, 0L, 0);   
  9264.            /*  seek back to beginning of  file */
  9265.            r = write(fd, "XX", 2);
  9266.            assert(r == 2);
  9267.            close(fd);
  9268.         }
  9269.  
  9270.         -1 > sampleprg
  9271.         1> type t:xx XXBar
  9272.         1>
  9273.  
  9274. dice/x.a                                                            dice/x.a
  9275.  
  9276.     FUNCTION
  9277.         autoinit terminating tags
  9278.  
  9279.     LIBRARY
  9280.         TBA
  9281.  
  9282.     SYNTAX
  9283.         TBA
  9284.  
  9285.     DESCRIPTION
  9286.         `The X.O module is the last object module in the link line DCC
  9287.         specifies to DLINK when linking an executable.  This module terminates
  9288.         the autoinit and autoexit sections with an RTS allowing the base of
  9289.         the section(s) to be called by the startup and exit code.
  9290.         autoinit/exit sections work as follows: any object module may define a
  9291.         specially named section which will be linked, in sequence, with other
  9292.         module's sections of the same name.  These sections contain only code
  9293.         and NO RTS.  The terminating module X.O adds a single RTS to each
  9294.         section allowing the base of the section to be called by the
  9295.         startup/exit module (C.O), propogating through all autoinit/exit
  9296.         routines before hitting the RTS placed in the section by X.O. DICE
  9297.         uses autoinit/exit sections to handle the following things:
  9298.  
  9299.         11) Code to initialize initialized data containing references to other
  9300.         11) initialized data (i.e.  int a, *b = &a;) when the code must be
  9301.         11) made residentable.  This precludes the need for the startup code
  9302.         11) to handle Data-Data Reloc32's for resident code.
  9303.  
  9304.         12) Code to open libraries whos base variables are referenced but
  9305.         12) never declared. _DOSBase and the various floating point libraries
  9306.         12) are automatically opened in this way whenever library calls to
  9307.         12) them are made. This precludes the need for DICE to have massive,
  9308.         12) complex, and many times unncessary code in c.lib to handle these
  9309.         12) situations.
  9310.  
  9311.         13) Code to close libraries that were openned by (2) on exit.
  9312.  
  9313.         14) Entry points for the special __autoinit keyword (registered
  9314.         14) versions of DICE only).
  9315.  
  9316.     INPUTS
  9317.         TBA
  9318.  
  9319.     RESULTS
  9320.         TBA
  9321.  
  9322.     SEE ALSO
  9323.         c.a
  9324.  
  9325.     EXAMPLE
  9326.         TBA
  9327.  
  9328.